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 | |
Anna Schumaker | 6de7e12 | 2017-01-09 16:51:52 -0500 | [diff] [blame] | 625 | static 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 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 632 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 633 | goto out_sleep; |
| 634 | |
| 635 | slot = nfs4_alloc_slot(tbl); |
| 636 | if (IS_ERR(slot)) { |
| 637 | if (slot == ERR_PTR(-ENOMEM)) |
| 638 | task->tk_timeout = HZ >> 2; |
| 639 | goto out_sleep; |
| 640 | } |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 641 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 642 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 643 | args->sa_slot = slot; |
| 644 | res->sr_slot = slot; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 645 | return 0; |
| 646 | |
| 647 | out_sleep: |
| 648 | if (args->sa_privileged) |
| 649 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 650 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 651 | else |
| 652 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 653 | return -EAGAIN; |
| 654 | } |
| 655 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 656 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 657 | { |
| 658 | struct nfs4_slot *slot = res->sr_slot; |
| 659 | struct nfs4_slot_table *tbl; |
| 660 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 661 | tbl = slot->table; |
| 662 | spin_lock(&tbl->slot_tbl_lock); |
| 663 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 664 | nfs4_free_slot(tbl, slot); |
| 665 | spin_unlock(&tbl->slot_tbl_lock); |
| 666 | |
| 667 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static int nfs40_sequence_done(struct rpc_task *task, |
| 671 | struct nfs4_sequence_res *res) |
| 672 | { |
| 673 | if (res->sr_slot != NULL) |
| 674 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 675 | return 1; |
| 676 | } |
| 677 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 678 | #if defined(CONFIG_NFS_V4_1) |
| 679 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 680 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 681 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 682 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 683 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 684 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 685 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 686 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 687 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 688 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 689 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 690 | /* Bump the slot sequence number */ |
| 691 | if (slot->seq_done) |
| 692 | slot->seq_nr++; |
| 693 | slot->seq_done = 0; |
| 694 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 695 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 696 | /* Be nice to the server: try to ensure that the last transmitted |
| 697 | * value for highest_user_slotid <= target_highest_slotid |
| 698 | */ |
| 699 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 700 | send_new_highest_used_slotid = true; |
| 701 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 702 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 703 | send_new_highest_used_slotid = false; |
| 704 | goto out_unlock; |
| 705 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 706 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 707 | |
| 708 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 709 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 710 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 711 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 712 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 713 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 714 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 715 | if (waitqueue_active(&tbl->slot_waitq)) |
| 716 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 717 | } |
| 718 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 719 | static int nfs41_sequence_process(struct rpc_task *task, |
| 720 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 721 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 722 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 723 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 724 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 725 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 726 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 727 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 728 | if (slot == NULL) |
| 729 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 730 | /* don't increment the sequence number if the task wasn't sent */ |
| 731 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 732 | goto out; |
| 733 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 734 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 735 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | if (slot->interrupted) { |
| 737 | slot->interrupted = 0; |
| 738 | interrupted = true; |
| 739 | } |
| 740 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 741 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 742 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 743 | switch (res->sr_status) { |
| 744 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 745 | /* If previous op on slot was interrupted and we reused |
| 746 | * the seq# and got a reply from the cache, then retry |
| 747 | */ |
| 748 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 749 | ++slot->seq_nr; |
| 750 | goto retry_nowait; |
| 751 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 752 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 753 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 754 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 755 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 756 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 757 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 758 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 759 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 760 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 761 | case 1: |
| 762 | /* |
| 763 | * sr_status remains 1 if an RPC level error occurred. |
| 764 | * The server may or may not have processed the sequence |
| 765 | * operation.. |
| 766 | * Mark the slot as having hosted an interrupted RPC call. |
| 767 | */ |
| 768 | slot->interrupted = 1; |
| 769 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 770 | case -NFS4ERR_DELAY: |
| 771 | /* The server detected a resend of the RPC call and |
| 772 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 773 | * of RFC5661. |
| 774 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 775 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 776 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 777 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 778 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 779 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 780 | case -NFS4ERR_BADSLOT: |
| 781 | /* |
| 782 | * The slot id we used was probably retired. Try again |
| 783 | * using a different slot id. |
| 784 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 785 | goto retry_nowait; |
| 786 | case -NFS4ERR_SEQ_MISORDERED: |
| 787 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 788 | * Was the last operation on this sequence interrupted? |
| 789 | * If so, retry after bumping the sequence number. |
| 790 | */ |
| 791 | if (interrupted) { |
| 792 | ++slot->seq_nr; |
| 793 | goto retry_nowait; |
| 794 | } |
| 795 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 796 | * Could this slot have been previously retired? |
| 797 | * If so, then the server may be expecting seq_nr = 1! |
| 798 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 799 | if (slot->seq_nr != 1) { |
| 800 | slot->seq_nr = 1; |
| 801 | goto retry_nowait; |
| 802 | } |
| 803 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 804 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 805 | ++slot->seq_nr; |
| 806 | goto retry_nowait; |
Trond Myklebust | 2cf10cd | 2016-12-04 19:26:40 -0500 | [diff] [blame] | 807 | case -NFS4ERR_DEADSESSION: |
| 808 | case -NFS4ERR_BADSESSION: |
| 809 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 810 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 811 | default: |
| 812 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 813 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 814 | } |
| 815 | out: |
| 816 | /* The session may be reset by one of the error handlers. */ |
| 817 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 818 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 819 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 820 | retry_nowait: |
| 821 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 822 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 823 | task->tk_status = 0; |
| 824 | ret = 0; |
| 825 | } |
| 826 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 827 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 828 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | goto out; |
| 830 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 831 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 832 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 833 | |
| 834 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 835 | { |
| 836 | if (!nfs41_sequence_process(task, res)) |
| 837 | return 0; |
| 838 | if (res->sr_slot != NULL) |
| 839 | nfs41_sequence_free_slot(res); |
| 840 | return 1; |
| 841 | |
| 842 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 844 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 845 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 846 | { |
| 847 | if (res->sr_slot == NULL) |
| 848 | return 1; |
| 849 | if (res->sr_slot->table->session != NULL) |
| 850 | return nfs41_sequence_process(task, res); |
| 851 | return nfs40_sequence_done(task, res); |
| 852 | } |
| 853 | |
| 854 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 855 | { |
| 856 | if (res->sr_slot != NULL) { |
| 857 | if (res->sr_slot->table->session != NULL) |
| 858 | nfs41_sequence_free_slot(res); |
| 859 | else |
| 860 | nfs40_sequence_free_slot(res); |
| 861 | } |
| 862 | } |
| 863 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 864 | 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] | 865 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 866 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 867 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 868 | if (!res->sr_slot->table->session) |
| 869 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 870 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 871 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 872 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 873 | |
Anna Schumaker | 6de7e12 | 2017-01-09 16:51:52 -0500 | [diff] [blame] | 874 | static int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 875 | struct nfs4_sequence_args *args, |
| 876 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | struct rpc_task *task) |
| 878 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 879 | struct nfs4_slot *slot; |
| 880 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 881 | |
| 882 | dprintk("--> %s\n", __func__); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 883 | tbl = &session->fc_slot_table; |
| 884 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 885 | task->tk_timeout = 0; |
| 886 | |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 887 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 888 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 889 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 890 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 891 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 894 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 895 | if (IS_ERR(slot)) { |
| 896 | /* If out of memory, try again in 1/4 second */ |
| 897 | if (slot == ERR_PTR(-ENOMEM)) |
| 898 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 899 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 900 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 901 | } |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 902 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 903 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 904 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 905 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 906 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 907 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 908 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 909 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 910 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 911 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 912 | /* |
| 913 | * sr_status is only set in decode_sequence, and so will remain |
| 914 | * set to 1 if an rpc level failure occurs. |
| 915 | */ |
| 916 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 917 | trace_nfs4_setup_sequence(session, args); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 918 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 919 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 920 | /* Privileged tasks are queued with top priority */ |
| 921 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 922 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 923 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 924 | else |
| 925 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 926 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 927 | } |
| 928 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 929 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 930 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 931 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 932 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 933 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 934 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 935 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 936 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 939 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 940 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 941 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 942 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 943 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 944 | } |
| 945 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 946 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 948 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 949 | }; |
| 950 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 951 | #else /* !CONFIG_NFS_V4_1 */ |
| 952 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 953 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 954 | { |
| 955 | return nfs40_sequence_done(task, res); |
| 956 | } |
| 957 | |
| 958 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 959 | { |
| 960 | if (res->sr_slot != NULL) |
| 961 | nfs40_sequence_free_slot(res); |
| 962 | } |
| 963 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 964 | int nfs4_sequence_done(struct rpc_task *task, |
| 965 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 966 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 967 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 968 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 969 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 970 | |
| 971 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 972 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 973 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 974 | struct nfs4_sequence_args *args, |
| 975 | struct nfs4_sequence_res *res, |
| 976 | struct rpc_task *task) |
| 977 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 978 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame^] | 979 | struct nfs4_slot_table *tbl = session ? &session->fc_slot_table : |
| 980 | client->cl_slot_tbl; |
| 981 | int ret; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 982 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 983 | /* slot already allocated? */ |
| 984 | if (res->sr_slot != NULL) |
| 985 | goto out_start; |
| 986 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame^] | 987 | spin_lock(&tbl->slot_tbl_lock); |
| 988 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 989 | #if defined(CONFIG_NFS_V4_1) |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 990 | if (session) |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame^] | 991 | ret = nfs41_setup_sequence(session, args, res, task); |
| 992 | else |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 993 | #endif /* CONFIG_NFS_V4_1 */ |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame^] | 994 | ret = nfs40_setup_sequence(client->cl_slot_tbl, args, res, task); |
| 995 | |
| 996 | spin_unlock(&tbl->slot_tbl_lock); |
| 997 | if (ret < 0) |
| 998 | return ret; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 999 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1000 | out_start: |
| 1001 | rpc_call_start(task); |
| 1002 | return 0; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1003 | } |
| 1004 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1005 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1006 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1007 | { |
| 1008 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1009 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1010 | data->seq_args, data->seq_res, task); |
| 1011 | } |
| 1012 | |
| 1013 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1014 | { |
| 1015 | struct nfs4_call_sync_data *data = calldata; |
| 1016 | nfs4_sequence_done(task, data->seq_res); |
| 1017 | } |
| 1018 | |
| 1019 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1020 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1021 | .rpc_call_done = nfs40_call_sync_done, |
| 1022 | }; |
| 1023 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1024 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1025 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1026 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1027 | struct nfs4_sequence_args *args, |
| 1028 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1029 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1030 | int ret; |
| 1031 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1032 | struct nfs_client *clp = server->nfs_client; |
| 1033 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1034 | .seq_server = server, |
| 1035 | .seq_args = args, |
| 1036 | .seq_res = res, |
| 1037 | }; |
| 1038 | struct rpc_task_setup task_setup = { |
| 1039 | .rpc_client = clnt, |
| 1040 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1041 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1042 | .callback_data = &data |
| 1043 | }; |
| 1044 | |
| 1045 | task = rpc_run_task(&task_setup); |
| 1046 | if (IS_ERR(task)) |
| 1047 | ret = PTR_ERR(task); |
| 1048 | else { |
| 1049 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1050 | rpc_put_task(task); |
| 1051 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | return ret; |
| 1053 | } |
| 1054 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1055 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1056 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1057 | struct rpc_message *msg, |
| 1058 | struct nfs4_sequence_args *args, |
| 1059 | struct nfs4_sequence_res *res, |
| 1060 | int cache_reply) |
| 1061 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1062 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1063 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1066 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1067 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | { |
| 1069 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1070 | |
| 1071 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1072 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1073 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1074 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1075 | nfsi->attrtimeo_timestamp = jiffies; |
| 1076 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1078 | if (cinfo->before != dir->i_version) |
| 1079 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1080 | NFS_INO_INVALID_ACL; |
| 1081 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1082 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1083 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1084 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1085 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | spin_unlock(&dir->i_lock); |
| 1087 | } |
| 1088 | |
| 1089 | struct nfs4_opendata { |
| 1090 | struct kref kref; |
| 1091 | struct nfs_openargs o_arg; |
| 1092 | struct nfs_openres o_res; |
| 1093 | struct nfs_open_confirmargs c_arg; |
| 1094 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1095 | struct nfs4_string owner_name; |
| 1096 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1097 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1099 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1101 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | struct nfs4_state_owner *owner; |
| 1103 | struct nfs4_state *state; |
| 1104 | struct iattr attrs; |
| 1105 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1106 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1107 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1108 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1109 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | int cancelled; |
| 1111 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1112 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1113 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1114 | int err, struct nfs4_exception *exception) |
| 1115 | { |
| 1116 | if (err != -EINVAL) |
| 1117 | return false; |
| 1118 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1119 | return false; |
| 1120 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1121 | exception->retry = 1; |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1125 | static u32 |
| 1126 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1127 | fmode_t fmode, int openflags) |
| 1128 | { |
| 1129 | u32 res = 0; |
| 1130 | |
| 1131 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1132 | case FMODE_READ: |
| 1133 | res = NFS4_SHARE_ACCESS_READ; |
| 1134 | break; |
| 1135 | case FMODE_WRITE: |
| 1136 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1137 | break; |
| 1138 | case FMODE_READ|FMODE_WRITE: |
| 1139 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1140 | } |
| 1141 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1142 | goto out; |
| 1143 | /* Want no delegation if we're using O_DIRECT */ |
| 1144 | if (openflags & O_DIRECT) |
| 1145 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1146 | out: |
| 1147 | return res; |
| 1148 | } |
| 1149 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1150 | static enum open_claim_type4 |
| 1151 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1152 | enum open_claim_type4 claim) |
| 1153 | { |
| 1154 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1155 | return claim; |
| 1156 | switch (claim) { |
| 1157 | default: |
| 1158 | return claim; |
| 1159 | case NFS4_OPEN_CLAIM_FH: |
| 1160 | return NFS4_OPEN_CLAIM_NULL; |
| 1161 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1162 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1163 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1164 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1165 | } |
| 1166 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
| 1168 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1169 | { |
| 1170 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1171 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1172 | p->o_res.seqid = p->o_arg.seqid; |
| 1173 | p->c_res.seqid = p->c_arg.seqid; |
| 1174 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1175 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1176 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1177 | 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] | 1178 | } |
| 1179 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1180 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1181 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1182 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1183 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1184 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1185 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1186 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1187 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1188 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1190 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1191 | struct nfs4_opendata *p; |
| 1192 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1193 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1194 | if (p == NULL) |
| 1195 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1196 | |
| 1197 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1198 | if (IS_ERR(p->f_label)) |
| 1199 | goto err_free_p; |
| 1200 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1201 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1202 | if (IS_ERR(p->a_label)) |
| 1203 | goto err_free_f; |
| 1204 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1205 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1206 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1207 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1208 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1209 | nfs_sb_active(dentry->d_sb); |
| 1210 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1211 | p->dir = parent; |
| 1212 | p->owner = sp; |
| 1213 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1214 | p->o_arg.open_flags = flags; |
| 1215 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1216 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1217 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1218 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1219 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1220 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1221 | * will return permission denied for all bits until close */ |
| 1222 | if (!(flags & O_EXCL)) { |
| 1223 | /* ask server to check for all possible rights as results |
| 1224 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1225 | switch (p->o_arg.claim) { |
| 1226 | default: |
| 1227 | break; |
| 1228 | case NFS4_OPEN_CLAIM_NULL: |
| 1229 | case NFS4_OPEN_CLAIM_FH: |
| 1230 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1231 | NFS4_ACCESS_MODIFY | |
| 1232 | NFS4_ACCESS_EXTEND | |
| 1233 | NFS4_ACCESS_EXECUTE; |
| 1234 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1235 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1236 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1237 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1238 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1239 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1240 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1241 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1242 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1243 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1244 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1245 | case NFS4_OPEN_CLAIM_NULL: |
| 1246 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1247 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1248 | p->o_arg.fh = NFS_FH(dir); |
| 1249 | break; |
| 1250 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1251 | case NFS4_OPEN_CLAIM_FH: |
| 1252 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1253 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1254 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1255 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1256 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1257 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1258 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1259 | p->o_arg.u.attrs = &p->attrs; |
| 1260 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1261 | |
| 1262 | verf[0] = jiffies; |
| 1263 | verf[1] = current->pid; |
| 1264 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1265 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1266 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1267 | p->c_arg.fh = &p->o_res.fh; |
| 1268 | p->c_arg.stateid = &p->o_res.stateid; |
| 1269 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1270 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1271 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1272 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1273 | |
| 1274 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1275 | nfs4_label_free(p->a_label); |
| 1276 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1277 | nfs4_label_free(p->f_label); |
| 1278 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1279 | kfree(p); |
| 1280 | err: |
| 1281 | dput(parent); |
| 1282 | return NULL; |
| 1283 | } |
| 1284 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1285 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1286 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1287 | struct nfs4_opendata *p = container_of(kref, |
| 1288 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1289 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1290 | |
| 1291 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1292 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1293 | if (p->state != NULL) |
| 1294 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1295 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1296 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1297 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1298 | nfs4_label_free(p->f_label); |
| 1299 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1300 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1301 | dput(p->dentry); |
| 1302 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1303 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1304 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1305 | kfree(p); |
| 1306 | } |
| 1307 | |
| 1308 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1309 | { |
| 1310 | if (p != NULL) |
| 1311 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1312 | } |
| 1313 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1314 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1315 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1316 | int ret; |
| 1317 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1318 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1319 | return ret; |
| 1320 | } |
| 1321 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1322 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1323 | fmode_t fmode) |
| 1324 | { |
| 1325 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1326 | case FMODE_READ|FMODE_WRITE: |
| 1327 | return state->n_rdwr != 0; |
| 1328 | case FMODE_WRITE: |
| 1329 | return state->n_wronly != 0; |
| 1330 | case FMODE_READ: |
| 1331 | return state->n_rdonly != 0; |
| 1332 | } |
| 1333 | WARN_ON_ONCE(1); |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1337 | 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] | 1338 | { |
| 1339 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1340 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1341 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1342 | goto out; |
| 1343 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1344 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1345 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1346 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1347 | break; |
| 1348 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1349 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1350 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1351 | break; |
| 1352 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1353 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1354 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1355 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1356 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1357 | return ret; |
| 1358 | } |
| 1359 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1360 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1361 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1362 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1363 | if (delegation == NULL) |
| 1364 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1365 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1366 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1367 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1368 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1369 | switch (claim) { |
| 1370 | case NFS4_OPEN_CLAIM_NULL: |
| 1371 | case NFS4_OPEN_CLAIM_FH: |
| 1372 | break; |
| 1373 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1374 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1375 | break; |
| 1376 | default: |
| 1377 | return 0; |
| 1378 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1379 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1380 | return 1; |
| 1381 | } |
| 1382 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1384 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1385 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1386 | case FMODE_WRITE: |
| 1387 | state->n_wronly++; |
| 1388 | break; |
| 1389 | case FMODE_READ: |
| 1390 | state->n_rdonly++; |
| 1391 | break; |
| 1392 | case FMODE_READ|FMODE_WRITE: |
| 1393 | state->n_rdwr++; |
| 1394 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1395 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1398 | #ifdef CONFIG_NFS_V4_1 |
| 1399 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1400 | { |
| 1401 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1402 | return true; |
| 1403 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1404 | return true; |
| 1405 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1406 | return true; |
| 1407 | return false; |
| 1408 | } |
| 1409 | #endif /* CONFIG_NFS_V4_1 */ |
| 1410 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1411 | static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1412 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1413 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1414 | bool need_recover = false; |
| 1415 | |
| 1416 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1417 | need_recover = true; |
| 1418 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1419 | need_recover = true; |
| 1420 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1421 | need_recover = true; |
| 1422 | if (need_recover) |
| 1423 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1424 | } |
| 1425 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1426 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1427 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1428 | { |
| 1429 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1430 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1431 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1432 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1433 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1434 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1435 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1436 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1437 | return true; |
| 1438 | return false; |
| 1439 | } |
| 1440 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1441 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1442 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1443 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1444 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1445 | if (state->n_wronly) |
| 1446 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1447 | if (state->n_rdonly) |
| 1448 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1449 | if (state->n_rdwr) |
| 1450 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1451 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1452 | } |
| 1453 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1454 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1455 | nfs4_stateid *stateid, fmode_t fmode) |
| 1456 | { |
| 1457 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1458 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1459 | case FMODE_WRITE: |
| 1460 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1461 | break; |
| 1462 | case FMODE_READ: |
| 1463 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1464 | break; |
| 1465 | case 0: |
| 1466 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1467 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1468 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1469 | } |
| 1470 | if (stateid == NULL) |
| 1471 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1472 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1473 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1474 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1475 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1476 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1477 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1478 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1479 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1480 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1481 | } |
| 1482 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1483 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1484 | nfs4_stateid *arg_stateid, |
| 1485 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1486 | { |
| 1487 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1488 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1489 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1490 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1491 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1492 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1493 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1496 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1497 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1498 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1499 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1501 | case FMODE_READ: |
| 1502 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1503 | break; |
| 1504 | case FMODE_WRITE: |
| 1505 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1506 | break; |
| 1507 | case FMODE_READ|FMODE_WRITE: |
| 1508 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1509 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1510 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1511 | return; |
| 1512 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1513 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1514 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1515 | } |
| 1516 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1517 | static void __update_open_stateid(struct nfs4_state *state, |
| 1518 | const nfs4_stateid *open_stateid, |
| 1519 | const nfs4_stateid *deleg_stateid, |
| 1520 | fmode_t fmode, |
| 1521 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1523 | /* |
| 1524 | * Protect the call to nfs4_state_set_mode_locked and |
| 1525 | * serialise the stateid update |
| 1526 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1527 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1528 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1529 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1530 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1531 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1532 | } |
| 1533 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1534 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1535 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1536 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1537 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1540 | static int update_open_stateid(struct nfs4_state *state, |
| 1541 | const nfs4_stateid *open_stateid, |
| 1542 | const nfs4_stateid *delegation, |
| 1543 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1544 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1545 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1546 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1547 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1548 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1549 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1550 | int ret = 0; |
| 1551 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1552 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1553 | |
| 1554 | rcu_read_lock(); |
| 1555 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1556 | if (deleg_cur == NULL) |
| 1557 | goto no_delegation; |
| 1558 | |
| 1559 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1560 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1561 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1562 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1563 | goto no_delegation_unlock; |
| 1564 | |
| 1565 | if (delegation == NULL) |
| 1566 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1567 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1568 | goto no_delegation_unlock; |
| 1569 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1570 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1571 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1572 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1573 | ret = 1; |
| 1574 | no_delegation_unlock: |
| 1575 | spin_unlock(&deleg_cur->lock); |
| 1576 | no_delegation: |
| 1577 | rcu_read_unlock(); |
| 1578 | |
| 1579 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1580 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1581 | ret = 1; |
| 1582 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1583 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1584 | nfs4_schedule_state_manager(clp); |
| 1585 | if (freeme.type != 0) |
| 1586 | nfs4_test_and_free_stateid(server, &freeme, |
| 1587 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1588 | |
| 1589 | return ret; |
| 1590 | } |
| 1591 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1592 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1593 | const nfs4_stateid *stateid) |
| 1594 | { |
| 1595 | struct nfs4_state *state = lsp->ls_state; |
| 1596 | bool ret = false; |
| 1597 | |
| 1598 | spin_lock(&state->state_lock); |
| 1599 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1600 | goto out_noupdate; |
| 1601 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1602 | goto out_noupdate; |
| 1603 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1604 | ret = true; |
| 1605 | out_noupdate: |
| 1606 | spin_unlock(&state->state_lock); |
| 1607 | return ret; |
| 1608 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1609 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1610 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1611 | { |
| 1612 | struct nfs_delegation *delegation; |
| 1613 | |
| 1614 | rcu_read_lock(); |
| 1615 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1616 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1617 | rcu_read_unlock(); |
| 1618 | return; |
| 1619 | } |
| 1620 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1621 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1624 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1625 | { |
| 1626 | struct nfs4_state *state = opendata->state; |
| 1627 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1628 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1629 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1630 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1631 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1632 | nfs4_stateid stateid; |
| 1633 | int ret = -EAGAIN; |
| 1634 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1635 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1636 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1637 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1638 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1639 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1640 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1641 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1642 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1643 | rcu_read_lock(); |
| 1644 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1645 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1646 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1647 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1648 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1649 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1650 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1651 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1652 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1653 | if (!opendata->is_recover) { |
| 1654 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1655 | if (ret != 0) |
| 1656 | goto out; |
| 1657 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1658 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1659 | |
| 1660 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1661 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1662 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1663 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1664 | out: |
| 1665 | return ERR_PTR(ret); |
| 1666 | out_return_state: |
| 1667 | atomic_inc(&state->count); |
| 1668 | return state; |
| 1669 | } |
| 1670 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1671 | static void |
| 1672 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1673 | { |
| 1674 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1675 | struct nfs_delegation *delegation; |
| 1676 | int delegation_flags = 0; |
| 1677 | |
| 1678 | rcu_read_lock(); |
| 1679 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1680 | if (delegation) |
| 1681 | delegation_flags = delegation->flags; |
| 1682 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1683 | switch (data->o_arg.claim) { |
| 1684 | default: |
| 1685 | break; |
| 1686 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1687 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1688 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1689 | "returning a delegation for " |
| 1690 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1691 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1692 | return; |
| 1693 | } |
| 1694 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1695 | nfs_inode_set_delegation(state->inode, |
| 1696 | data->owner->so_cred, |
| 1697 | &data->o_res); |
| 1698 | else |
| 1699 | nfs_inode_reclaim_delegation(state->inode, |
| 1700 | data->owner->so_cred, |
| 1701 | &data->o_res); |
| 1702 | } |
| 1703 | |
| 1704 | /* |
| 1705 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1706 | * and update the nfs4_state. |
| 1707 | */ |
| 1708 | static struct nfs4_state * |
| 1709 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1710 | { |
| 1711 | struct inode *inode = data->state->inode; |
| 1712 | struct nfs4_state *state = data->state; |
| 1713 | int ret; |
| 1714 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1715 | if (!data->rpc_done) { |
| 1716 | if (data->rpc_status) { |
| 1717 | ret = data->rpc_status; |
| 1718 | goto err; |
| 1719 | } |
| 1720 | /* cached opens have already been processed */ |
| 1721 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1724 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1725 | if (ret) |
| 1726 | goto err; |
| 1727 | |
| 1728 | if (data->o_res.delegation_type != 0) |
| 1729 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1730 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1731 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1732 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1733 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1734 | |
| 1735 | return state; |
| 1736 | err: |
| 1737 | return ERR_PTR(ret); |
| 1738 | |
| 1739 | } |
| 1740 | |
| 1741 | static struct nfs4_state * |
| 1742 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1743 | { |
| 1744 | struct inode *inode; |
| 1745 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1746 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1747 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1748 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1749 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1750 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1751 | goto out; |
| 1752 | } |
| 1753 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1754 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1755 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1756 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1757 | 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] | 1758 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1759 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1760 | goto err; |
| 1761 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1762 | state = nfs4_get_open_state(inode, data->owner); |
| 1763 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1764 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1765 | if (data->o_res.delegation_type != 0) |
| 1766 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1767 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1768 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1769 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1770 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1771 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1772 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1773 | err_put_inode: |
| 1774 | iput(inode); |
| 1775 | err: |
| 1776 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1777 | } |
| 1778 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1779 | static struct nfs4_state * |
| 1780 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1781 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1782 | struct nfs4_state *ret; |
| 1783 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1784 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1785 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1786 | else |
| 1787 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1788 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1789 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1792 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1793 | { |
| 1794 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1795 | struct nfs_open_context *ctx; |
| 1796 | |
| 1797 | spin_lock(&state->inode->i_lock); |
| 1798 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1799 | if (ctx->state != state) |
| 1800 | continue; |
| 1801 | get_nfs_open_context(ctx); |
| 1802 | spin_unlock(&state->inode->i_lock); |
| 1803 | return ctx; |
| 1804 | } |
| 1805 | spin_unlock(&state->inode->i_lock); |
| 1806 | return ERR_PTR(-ENOENT); |
| 1807 | } |
| 1808 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1809 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1810 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1811 | { |
| 1812 | struct nfs4_opendata *opendata; |
| 1813 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1814 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1815 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1816 | if (opendata == NULL) |
| 1817 | return ERR_PTR(-ENOMEM); |
| 1818 | opendata->state = state; |
| 1819 | atomic_inc(&state->count); |
| 1820 | return opendata; |
| 1821 | } |
| 1822 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1823 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1824 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1825 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1826 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1827 | int ret; |
| 1828 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1829 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1830 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1831 | opendata->o_arg.open_flags = 0; |
| 1832 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1833 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1834 | NFS_SB(opendata->dentry->d_sb), |
| 1835 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1836 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1837 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1838 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1839 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1840 | if (ret != 0) |
| 1841 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1842 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1843 | if (IS_ERR(newstate)) |
| 1844 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1845 | if (newstate != opendata->state) |
| 1846 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1847 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1848 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1852 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1853 | int ret; |
| 1854 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1855 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1856 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1857 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1858 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1859 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1860 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1861 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1862 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1863 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1864 | if (ret != 0) |
| 1865 | return ret; |
| 1866 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1867 | if (ret != 0) |
| 1868 | return ret; |
| 1869 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1870 | if (ret != 0) |
| 1871 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1872 | /* |
| 1873 | * We may have performed cached opens for all three recoveries. |
| 1874 | * Check if we need to update the current stateid. |
| 1875 | */ |
| 1876 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1877 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1878 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1879 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1880 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1881 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1882 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1883 | return 0; |
| 1884 | } |
| 1885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | /* |
| 1887 | * OPEN_RECLAIM: |
| 1888 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1890 | 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] | 1891 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1892 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1893 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1894 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | int status; |
| 1896 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1897 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1898 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1899 | if (IS_ERR(opendata)) |
| 1900 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1901 | rcu_read_lock(); |
| 1902 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1903 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1904 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1905 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1906 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1907 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1908 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | return status; |
| 1910 | } |
| 1911 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1912 | 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] | 1913 | { |
| 1914 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1915 | struct nfs4_exception exception = { }; |
| 1916 | int err; |
| 1917 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1918 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1919 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1920 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1921 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1922 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | } while (exception.retry); |
| 1926 | return err; |
| 1927 | } |
| 1928 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1929 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1930 | { |
| 1931 | struct nfs_open_context *ctx; |
| 1932 | int ret; |
| 1933 | |
| 1934 | ctx = nfs4_state_find_open_context(state); |
| 1935 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1936 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1937 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1938 | put_nfs_open_context(ctx); |
| 1939 | return ret; |
| 1940 | } |
| 1941 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1942 | 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] | 1943 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1944 | switch (err) { |
| 1945 | default: |
| 1946 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1947 | "%d.\n", __func__, err); |
| 1948 | case 0: |
| 1949 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1950 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1951 | case -ESTALE: |
| 1952 | break; |
| 1953 | case -NFS4ERR_BADSESSION: |
| 1954 | case -NFS4ERR_BADSLOT: |
| 1955 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1956 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1957 | case -NFS4ERR_DEADSESSION: |
| 1958 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1959 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1960 | return -EAGAIN; |
| 1961 | case -NFS4ERR_STALE_CLIENTID: |
| 1962 | case -NFS4ERR_STALE_STATEID: |
| 1963 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1964 | /* Don't recall a delegation if it was lost */ |
| 1965 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1966 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1967 | case -NFS4ERR_MOVED: |
| 1968 | nfs4_schedule_migration_recovery(server); |
| 1969 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1970 | case -NFS4ERR_LEASE_MOVED: |
| 1971 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1972 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1973 | case -NFS4ERR_DELEG_REVOKED: |
| 1974 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1975 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1976 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1977 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1978 | nfs_inode_find_state_and_recover(state->inode, |
| 1979 | stateid); |
| 1980 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1981 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1982 | case -NFS4ERR_DELAY: |
| 1983 | case -NFS4ERR_GRACE: |
| 1984 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1985 | ssleep(1); |
| 1986 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1987 | case -ENOMEM: |
| 1988 | case -NFS4ERR_DENIED: |
| 1989 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1990 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | return err; |
| 1993 | } |
| 1994 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1995 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1996 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1997 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1998 | { |
| 1999 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2000 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2001 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2002 | |
| 2003 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2004 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2005 | if (IS_ERR(opendata)) |
| 2006 | return PTR_ERR(opendata); |
| 2007 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2008 | write_seqlock(&state->seqlock); |
| 2009 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2010 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2011 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2012 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2013 | case FMODE_READ|FMODE_WRITE: |
| 2014 | case FMODE_WRITE: |
| 2015 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2016 | if (err) |
| 2017 | break; |
| 2018 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2019 | if (err) |
| 2020 | break; |
| 2021 | case FMODE_READ: |
| 2022 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2023 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2024 | nfs4_opendata_put(opendata); |
| 2025 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2026 | } |
| 2027 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2028 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2029 | { |
| 2030 | struct nfs4_opendata *data = calldata; |
| 2031 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2032 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2033 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2034 | } |
| 2035 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2036 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2037 | { |
| 2038 | struct nfs4_opendata *data = calldata; |
| 2039 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2040 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2041 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2042 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2043 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2044 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2045 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2046 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2047 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2048 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | static void nfs4_open_confirm_release(void *calldata) |
| 2052 | { |
| 2053 | struct nfs4_opendata *data = calldata; |
| 2054 | struct nfs4_state *state = NULL; |
| 2055 | |
| 2056 | /* If this request hasn't been cancelled, do nothing */ |
| 2057 | if (data->cancelled == 0) |
| 2058 | goto out_free; |
| 2059 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2060 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2061 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2062 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2063 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2064 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2065 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2066 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2070 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2071 | .rpc_call_done = nfs4_open_confirm_done, |
| 2072 | .rpc_release = nfs4_open_confirm_release, |
| 2073 | }; |
| 2074 | |
| 2075 | /* |
| 2076 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2077 | */ |
| 2078 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2079 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2080 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2081 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2082 | struct rpc_message msg = { |
| 2083 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2084 | .rpc_argp = &data->c_arg, |
| 2085 | .rpc_resp = &data->c_res, |
| 2086 | .rpc_cred = data->owner->so_cred, |
| 2087 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2088 | struct rpc_task_setup task_setup_data = { |
| 2089 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2090 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2091 | .callback_ops = &nfs4_open_confirm_ops, |
| 2092 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2093 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2094 | .flags = RPC_TASK_ASYNC, |
| 2095 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | int status; |
| 2097 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2098 | 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] | 2099 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2100 | data->rpc_done = 0; |
| 2101 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2102 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2103 | if (data->is_recover) |
| 2104 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2105 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2106 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2107 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2108 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2109 | if (status != 0) { |
| 2110 | data->cancelled = 1; |
| 2111 | smp_wmb(); |
| 2112 | } else |
| 2113 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2114 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | return status; |
| 2116 | } |
| 2117 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2118 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2120 | struct nfs4_opendata *data = calldata; |
| 2121 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2122 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2123 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2124 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2125 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2126 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2127 | /* |
| 2128 | * Check if we still need to send an OPEN call, or if we can use |
| 2129 | * a delegation instead. |
| 2130 | */ |
| 2131 | if (data->state != NULL) { |
| 2132 | struct nfs_delegation *delegation; |
| 2133 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2134 | 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] | 2135 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2136 | rcu_read_lock(); |
| 2137 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2138 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2139 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2140 | rcu_read_unlock(); |
| 2141 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2142 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2143 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2144 | switch (claim) { |
| 2145 | default: |
| 2146 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2147 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2148 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2149 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2150 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2151 | case NFS4_OPEN_CLAIM_FH: |
| 2152 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2153 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2154 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2155 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2156 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2157 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2158 | &data->o_res.seq_res, |
| 2159 | task) != 0) |
| 2160 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2161 | |
| 2162 | /* Set the create mode (note dependency on the session type) */ |
| 2163 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2164 | if (data->o_arg.open_flags & O_EXCL) { |
| 2165 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2166 | if (nfs4_has_persistent_session(clp)) |
| 2167 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2168 | else if (clp->cl_mvops->minor_version > 0) |
| 2169 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2170 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2171 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2172 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2173 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2174 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2175 | out_no_action: |
| 2176 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2177 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2178 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2179 | } |
| 2180 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2181 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2182 | { |
| 2183 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2185 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2186 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2187 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2188 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2189 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2190 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2191 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2192 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2193 | case S_IFREG: |
| 2194 | break; |
| 2195 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2196 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2197 | break; |
| 2198 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2199 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2200 | break; |
| 2201 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2202 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2203 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2204 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2205 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2206 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2207 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2208 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2209 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2210 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2211 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2212 | static void nfs4_open_release(void *calldata) |
| 2213 | { |
| 2214 | struct nfs4_opendata *data = calldata; |
| 2215 | struct nfs4_state *state = NULL; |
| 2216 | |
| 2217 | /* If this request hasn't been cancelled, do nothing */ |
| 2218 | if (data->cancelled == 0) |
| 2219 | goto out_free; |
| 2220 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2221 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2222 | goto out_free; |
| 2223 | /* In case we need an open_confirm, no cleanup! */ |
| 2224 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2225 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2226 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2227 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2228 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2229 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2230 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2234 | .rpc_call_prepare = nfs4_open_prepare, |
| 2235 | .rpc_call_done = nfs4_open_done, |
| 2236 | .rpc_release = nfs4_open_release, |
| 2237 | }; |
| 2238 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2239 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2240 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2241 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2242 | struct nfs_server *server = NFS_SERVER(dir); |
| 2243 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2244 | struct nfs_openres *o_res = &data->o_res; |
| 2245 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2246 | struct rpc_message msg = { |
| 2247 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2248 | .rpc_argp = o_arg, |
| 2249 | .rpc_resp = o_res, |
| 2250 | .rpc_cred = data->owner->so_cred, |
| 2251 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2252 | struct rpc_task_setup task_setup_data = { |
| 2253 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2254 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2255 | .callback_ops = &nfs4_open_ops, |
| 2256 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2257 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2258 | .flags = RPC_TASK_ASYNC, |
| 2259 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2260 | int status; |
| 2261 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2262 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2263 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2264 | data->rpc_done = 0; |
| 2265 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2266 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2267 | data->is_recover = 0; |
| 2268 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2269 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2270 | data->is_recover = 1; |
| 2271 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2272 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2273 | if (IS_ERR(task)) |
| 2274 | return PTR_ERR(task); |
| 2275 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2276 | if (status != 0) { |
| 2277 | data->cancelled = 1; |
| 2278 | smp_wmb(); |
| 2279 | } else |
| 2280 | status = data->rpc_status; |
| 2281 | rpc_put_task(task); |
| 2282 | |
| 2283 | return status; |
| 2284 | } |
| 2285 | |
| 2286 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2287 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2288 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2289 | struct nfs_openres *o_res = &data->o_res; |
| 2290 | int status; |
| 2291 | |
| 2292 | status = nfs4_run_open_task(data, 1); |
| 2293 | if (status != 0 || !data->rpc_done) |
| 2294 | return status; |
| 2295 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2296 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2297 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2298 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2299 | status = _nfs4_proc_open_confirm(data); |
| 2300 | if (status != 0) |
| 2301 | return status; |
| 2302 | } |
| 2303 | |
| 2304 | return status; |
| 2305 | } |
| 2306 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2307 | /* |
| 2308 | * Additional permission checks in order to distinguish between an |
| 2309 | * open for read, and an open for execute. This works around the |
| 2310 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2311 | * the same. |
| 2312 | * Note that in the non-execute case, we want to turn off permission |
| 2313 | * checking if we just created a new file (POSIX open() semantics). |
| 2314 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2315 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2316 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2317 | struct nfs4_state *state, fmode_t fmode, |
| 2318 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2319 | { |
| 2320 | struct nfs_access_entry cache; |
| 2321 | u32 mask; |
| 2322 | |
| 2323 | /* access call failed or for some reason the server doesn't |
| 2324 | * support any access modes -- defer access call until later */ |
| 2325 | if (opendata->o_res.access_supported == 0) |
| 2326 | return 0; |
| 2327 | |
| 2328 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2329 | /* |
| 2330 | * Use openflags to check for exec, because fmode won't |
| 2331 | * always have FMODE_EXEC set when file open for exec. |
| 2332 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2333 | if (openflags & __FMODE_EXEC) { |
| 2334 | /* ONLY check for exec rights */ |
| 2335 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2336 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2337 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2338 | |
| 2339 | cache.cred = cred; |
| 2340 | cache.jiffies = jiffies; |
| 2341 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2342 | nfs_access_add_cache(state->inode, &cache); |
| 2343 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2344 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2345 | return 0; |
| 2346 | |
| 2347 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2348 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2349 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2350 | } |
| 2351 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2352 | /* |
| 2353 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2354 | */ |
| 2355 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2356 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2357 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2358 | struct nfs_server *server = NFS_SERVER(dir); |
| 2359 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2360 | struct nfs_openres *o_res = &data->o_res; |
| 2361 | int status; |
| 2362 | |
| 2363 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2364 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2365 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2366 | if (status != 0) { |
| 2367 | if (status == -NFS4ERR_BADNAME && |
| 2368 | !(o_arg->open_flags & O_CREAT)) |
| 2369 | return -ENOENT; |
| 2370 | return status; |
| 2371 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2372 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2373 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2374 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2375 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2376 | if (o_arg->open_flags & O_EXCL) |
| 2377 | data->file_created = 1; |
| 2378 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2379 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2380 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2381 | update_changeattr(dir, &o_res->cinfo, |
| 2382 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2383 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2384 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2385 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2387 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2389 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | } |
| 2391 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2392 | 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] | 2393 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2396 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2397 | { |
| 2398 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2399 | } |
| 2400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | /* |
| 2402 | * OPEN_EXPIRED: |
| 2403 | * reclaim state on the server after a network partition. |
| 2404 | * Assumes caller holds the appropriate lock |
| 2405 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2406 | 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] | 2407 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2408 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2409 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2411 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2412 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2413 | if (IS_ERR(opendata)) |
| 2414 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2415 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2416 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2417 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2418 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2419 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2422 | 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] | 2423 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2424 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2425 | struct nfs4_exception exception = { }; |
| 2426 | int err; |
| 2427 | |
| 2428 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2429 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2430 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2431 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2432 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2433 | switch (err) { |
| 2434 | default: |
| 2435 | goto out; |
| 2436 | case -NFS4ERR_GRACE: |
| 2437 | case -NFS4ERR_DELAY: |
| 2438 | nfs4_handle_exception(server, err, &exception); |
| 2439 | err = 0; |
| 2440 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2441 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2442 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2443 | return err; |
| 2444 | } |
| 2445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2447 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2449 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2451 | ctx = nfs4_state_find_open_context(state); |
| 2452 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2453 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2454 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2455 | put_nfs_open_context(ctx); |
| 2456 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2459 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2460 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2461 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2462 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2463 | write_seqlock(&state->seqlock); |
| 2464 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2465 | write_sequnlock(&state->seqlock); |
| 2466 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2467 | } |
| 2468 | |
| 2469 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2470 | { |
| 2471 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2472 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2476 | { |
| 2477 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2478 | nfs40_clear_delegation_stateid(state); |
| 2479 | return nfs4_open_expired(sp, state); |
| 2480 | } |
| 2481 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2482 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2483 | nfs4_stateid *stateid, |
| 2484 | struct rpc_cred *cred) |
| 2485 | { |
| 2486 | return -NFS4ERR_BAD_STATEID; |
| 2487 | } |
| 2488 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2489 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2490 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2491 | nfs4_stateid *stateid, |
| 2492 | struct rpc_cred *cred) |
| 2493 | { |
| 2494 | int status; |
| 2495 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2496 | switch (stateid->type) { |
| 2497 | default: |
| 2498 | break; |
| 2499 | case NFS4_INVALID_STATEID_TYPE: |
| 2500 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2501 | return -NFS4ERR_BAD_STATEID; |
| 2502 | case NFS4_REVOKED_STATEID_TYPE: |
| 2503 | goto out_free; |
| 2504 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2505 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2506 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2507 | switch (status) { |
| 2508 | case -NFS4ERR_EXPIRED: |
| 2509 | case -NFS4ERR_ADMIN_REVOKED: |
| 2510 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2511 | break; |
| 2512 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2513 | return status; |
| 2514 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2515 | out_free: |
| 2516 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2517 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2518 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2519 | } |
| 2520 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2521 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2522 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2523 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2524 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2525 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2526 | struct rpc_cred *cred; |
| 2527 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2528 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2529 | /* Get the delegation credential for use by test/free_stateid */ |
| 2530 | rcu_read_lock(); |
| 2531 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2532 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2533 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2534 | return; |
| 2535 | } |
| 2536 | |
| 2537 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2538 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2539 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2540 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2541 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2542 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2543 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2544 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2545 | rcu_read_unlock(); |
| 2546 | return; |
| 2547 | } |
| 2548 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2549 | cred = get_rpccred(delegation->cred); |
| 2550 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2551 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2552 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2553 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2554 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2555 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2556 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2560 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2561 | * |
| 2562 | * @state: NFSv4 state for an inode |
| 2563 | * |
| 2564 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2565 | * Otherwise a negative NFS4ERR value is returned. |
| 2566 | */ |
| 2567 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2568 | { |
| 2569 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2570 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2571 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2572 | |
| 2573 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2574 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2575 | |
| 2576 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2577 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2578 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2579 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2580 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2581 | atomic_inc(&lsp->ls_count); |
| 2582 | spin_unlock(&state->state_lock); |
| 2583 | |
| 2584 | nfs4_put_lock_state(prev); |
| 2585 | prev = lsp; |
| 2586 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2587 | status = nfs41_test_and_free_expired_stateid(server, |
| 2588 | &lsp->ls_stateid, |
| 2589 | cred); |
| 2590 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2591 | if (status == -NFS4ERR_EXPIRED || |
| 2592 | status == -NFS4ERR_BAD_STATEID) { |
| 2593 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2594 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2595 | if (!recover_lost_locks) |
| 2596 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2597 | } else if (status != NFS_OK) { |
| 2598 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2599 | nfs4_put_lock_state(prev); |
| 2600 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2601 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2602 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2603 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2604 | } |
| 2605 | spin_unlock(&state->state_lock); |
| 2606 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2607 | out: |
| 2608 | return ret; |
| 2609 | } |
| 2610 | |
| 2611 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2612 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2613 | * |
| 2614 | * @state: NFSv4 state for an inode |
| 2615 | * |
| 2616 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2617 | * Otherwise a negative NFS4ERR value is returned. |
| 2618 | */ |
| 2619 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2620 | { |
| 2621 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2622 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2623 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2624 | int status; |
| 2625 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2626 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2627 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2628 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2629 | return NFS_OK; |
| 2630 | return -NFS4ERR_OPENMODE; |
| 2631 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2632 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2633 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2634 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2635 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2636 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2637 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2638 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2639 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2640 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2641 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2642 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2643 | if (status != NFS_OK) |
| 2644 | return status; |
| 2645 | if (nfs_open_stateid_recover_openmode(state)) |
| 2646 | return -NFS4ERR_OPENMODE; |
| 2647 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2651 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2652 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2653 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2654 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2655 | status = nfs41_check_expired_locks(state); |
| 2656 | if (status != NFS_OK) |
| 2657 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2658 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2659 | if (status != NFS_OK) |
| 2660 | status = nfs4_open_expired(sp, state); |
| 2661 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2662 | } |
| 2663 | #endif |
| 2664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2666 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2667 | * fields corresponding to attributes that were used to store the verifier. |
| 2668 | * Make sure we clobber those fields in the later setattr call |
| 2669 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2670 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2671 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2672 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2673 | const u32 *attrset = opendata->o_res.attrset; |
| 2674 | |
| 2675 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2676 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2677 | sattr->ia_valid |= ATTR_ATIME; |
| 2678 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2679 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2680 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2681 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2682 | |
| 2683 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2684 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2685 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2686 | sattr->ia_valid &= ~ATTR_MODE; |
| 2687 | |
| 2688 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2689 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2690 | } |
| 2691 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2692 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2693 | fmode_t fmode, |
| 2694 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2695 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2696 | { |
| 2697 | struct nfs4_state_owner *sp = opendata->owner; |
| 2698 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2699 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2700 | struct nfs4_state *state; |
| 2701 | unsigned int seq; |
| 2702 | int ret; |
| 2703 | |
| 2704 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2705 | |
| 2706 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2707 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2708 | goto out; |
| 2709 | |
| 2710 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2711 | ret = PTR_ERR(state); |
| 2712 | if (IS_ERR(state)) |
| 2713 | goto out; |
| 2714 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2715 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2716 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2717 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2718 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2719 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2720 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2721 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2722 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2723 | alias = d_exact_alias(dentry, state->inode); |
| 2724 | if (!alias) |
| 2725 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2726 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2727 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2728 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2729 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2730 | } |
| 2731 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2732 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2733 | } |
| 2734 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2735 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2736 | if (ret != 0) |
| 2737 | goto out; |
| 2738 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2739 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2740 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2741 | nfs_inode_attach_open_context(ctx); |
| 2742 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2743 | nfs4_schedule_stateid_recovery(server, state); |
| 2744 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2745 | out: |
| 2746 | return ret; |
| 2747 | } |
| 2748 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2749 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2750 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2752 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2753 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2754 | int flags, |
| 2755 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2756 | struct nfs4_label *label, |
| 2757 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | { |
| 2759 | struct nfs4_state_owner *sp; |
| 2760 | struct nfs4_state *state = NULL; |
| 2761 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2762 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2763 | struct dentry *dentry = ctx->dentry; |
| 2764 | struct rpc_cred *cred = ctx->cred; |
| 2765 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2766 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2767 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2768 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2769 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | |
| 2771 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2773 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2774 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2776 | goto out_err; |
| 2777 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2778 | status = nfs4_recover_expired_lease(server); |
| 2779 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2780 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2781 | if (d_really_is_positive(dentry)) |
| 2782 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2783 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2784 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2785 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2786 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2787 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2788 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2789 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2791 | if (label) { |
| 2792 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2793 | if (IS_ERR(olabel)) { |
| 2794 | status = PTR_ERR(olabel); |
| 2795 | goto err_opendata_put; |
| 2796 | } |
| 2797 | } |
| 2798 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2799 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2800 | if (!opendata->f_attr.mdsthreshold) { |
| 2801 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2802 | if (!opendata->f_attr.mdsthreshold) |
| 2803 | goto err_free_label; |
| 2804 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2805 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2806 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2807 | if (d_really_is_positive(dentry)) |
| 2808 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2809 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2810 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2811 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2812 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2813 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2814 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2815 | 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] | 2816 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2817 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2818 | /* |
| 2819 | * send create attributes which was not set by open |
| 2820 | * with an extra setattr. |
| 2821 | */ |
| 2822 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2823 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2824 | status = nfs4_do_setattr(state->inode, cred, |
| 2825 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2826 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2827 | if (status == 0) { |
| 2828 | nfs_setattr_update_inode(state->inode, sattr, |
| 2829 | opendata->o_res.f_attr); |
| 2830 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2831 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2832 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2833 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2834 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2835 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2836 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2837 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2838 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2839 | opendata->f_attr.mdsthreshold = NULL; |
| 2840 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2841 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2842 | nfs4_label_free(olabel); |
| 2843 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2844 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2847 | err_free_label: |
| 2848 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2849 | err_opendata_put: |
| 2850 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2851 | err_put_state_owner: |
| 2852 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | return status; |
| 2855 | } |
| 2856 | |
| 2857 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2858 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2859 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2860 | int flags, |
| 2861 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2862 | struct nfs4_label *label, |
| 2863 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2865 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | struct nfs4_exception exception = { }; |
| 2867 | struct nfs4_state *res; |
| 2868 | int status; |
| 2869 | |
| 2870 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2871 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2872 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2873 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | if (status == 0) |
| 2875 | break; |
| 2876 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2877 | * book-keeping w.r.t. state-changing operations |
| 2878 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2879 | * It is actually a sign of a bug on the client or on the server. |
| 2880 | * |
| 2881 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2882 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | * have unhashed the old state_owner for us, and that we can |
| 2884 | * therefore safely retry using a new one. We should still warn |
| 2885 | * the user though... |
| 2886 | */ |
| 2887 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2888 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2889 | " returned a bad sequence-id error!\n", |
| 2890 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | exception.retry = 1; |
| 2892 | continue; |
| 2893 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2894 | /* |
| 2895 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2896 | * state before it received the OPEN_CONFIRM. |
| 2897 | * Recover by retrying the request as per the discussion |
| 2898 | * on Page 181 of RFC3530. |
| 2899 | */ |
| 2900 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2901 | exception.retry = 1; |
| 2902 | continue; |
| 2903 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2904 | if (status == -EAGAIN) { |
| 2905 | /* We must have found a delegation */ |
| 2906 | exception.retry = 1; |
| 2907 | continue; |
| 2908 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2909 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2910 | continue; |
| 2911 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | status, &exception)); |
| 2913 | } while (exception.retry); |
| 2914 | return res; |
| 2915 | } |
| 2916 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2917 | static int _nfs4_do_setattr(struct inode *inode, |
| 2918 | struct nfs_setattrargs *arg, |
| 2919 | struct nfs_setattrres *res, |
| 2920 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2921 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2922 | { |
| 2923 | struct nfs_server *server = NFS_SERVER(inode); |
| 2924 | struct rpc_message msg = { |
| 2925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2926 | .rpc_argp = arg, |
| 2927 | .rpc_resp = res, |
| 2928 | .rpc_cred = cred, |
| 2929 | }; |
| 2930 | struct rpc_cred *delegation_cred = NULL; |
| 2931 | unsigned long timestamp = jiffies; |
| 2932 | fmode_t fmode; |
| 2933 | bool truncate; |
| 2934 | int status; |
| 2935 | |
| 2936 | nfs_fattr_init(res->fattr); |
| 2937 | |
| 2938 | /* Servers should only apply open mode checks for file size changes */ |
| 2939 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2940 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2941 | |
| 2942 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2943 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2944 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2945 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2946 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2947 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2948 | l_ctx = nfs_get_lock_context(ctx); |
| 2949 | if (IS_ERR(l_ctx)) |
| 2950 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2951 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2952 | &arg->stateid, &delegation_cred); |
| 2953 | nfs_put_lock_context(l_ctx); |
| 2954 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2955 | return -EBADF; |
| 2956 | } else |
| 2957 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2958 | if (delegation_cred) |
| 2959 | msg.rpc_cred = delegation_cred; |
| 2960 | |
| 2961 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2962 | |
| 2963 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2964 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2965 | renew_lease(server, timestamp); |
| 2966 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2967 | return status; |
| 2968 | } |
| 2969 | |
| 2970 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2971 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2972 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2973 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2975 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2976 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2978 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | .iap = sattr, |
| 2980 | .server = server, |
| 2981 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2982 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | }; |
| 2984 | struct nfs_setattrres res = { |
| 2985 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2986 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | .server = server, |
| 2988 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2989 | struct nfs4_exception exception = { |
| 2990 | .state = state, |
| 2991 | .inode = inode, |
| 2992 | .stateid = &arg.stateid, |
| 2993 | }; |
| 2994 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2996 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2997 | if (ilabel) |
| 2998 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3001 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3002 | switch (err) { |
| 3003 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3004 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3005 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3006 | "applying open mode checks to " |
| 3007 | "a SETATTR that is not " |
| 3008 | "changing file size.\n", |
| 3009 | server->nfs_client->cl_hostname); |
| 3010 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3011 | if (state && !(state->state & FMODE_WRITE)) { |
| 3012 | err = -EBADF; |
| 3013 | if (sattr->ia_valid & ATTR_OPEN) |
| 3014 | err = -EACCES; |
| 3015 | goto out; |
| 3016 | } |
| 3017 | } |
| 3018 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3020 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | return err; |
| 3022 | } |
| 3023 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3024 | static bool |
| 3025 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3026 | { |
| 3027 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3028 | return false; |
| 3029 | |
| 3030 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3031 | } |
| 3032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | struct nfs4_closedata { |
| 3034 | struct inode *inode; |
| 3035 | struct nfs4_state *state; |
| 3036 | struct nfs_closeargs arg; |
| 3037 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3038 | struct { |
| 3039 | struct nfs4_layoutreturn_args arg; |
| 3040 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3041 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3042 | u32 roc_barrier; |
| 3043 | bool roc; |
| 3044 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3045 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3046 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | }; |
| 3048 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3049 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3050 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3051 | struct nfs4_closedata *calldata = data; |
| 3052 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3053 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3054 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3055 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3056 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3057 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3058 | nfs4_put_open_state(calldata->state); |
| 3059 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3060 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3061 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3062 | kfree(calldata); |
| 3063 | } |
| 3064 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3065 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3067 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3070 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3072 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3073 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3074 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3075 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3076 | |
| 3077 | /* Handle Layoutreturn errors */ |
| 3078 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3079 | switch (calldata->res.lr_ret) { |
| 3080 | default: |
| 3081 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3082 | break; |
| 3083 | case 0: |
| 3084 | calldata->arg.lr_args = NULL; |
| 3085 | calldata->res.lr_res = NULL; |
| 3086 | break; |
| 3087 | case -NFS4ERR_ADMIN_REVOKED: |
| 3088 | case -NFS4ERR_DELEG_REVOKED: |
| 3089 | case -NFS4ERR_EXPIRED: |
| 3090 | case -NFS4ERR_BAD_STATEID: |
| 3091 | case -NFS4ERR_OLD_STATEID: |
| 3092 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3093 | case -NFS4ERR_WRONG_CRED: |
| 3094 | calldata->arg.lr_args = NULL; |
| 3095 | calldata->res.lr_res = NULL; |
| 3096 | calldata->res.lr_ret = 0; |
| 3097 | rpc_restart_call_prepare(task); |
| 3098 | return; |
| 3099 | } |
| 3100 | } |
| 3101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | /* hmm. we are done with the inode, and in the process of freeing |
| 3103 | * the state_owner. we keep this around to process errors |
| 3104 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | switch (task->tk_status) { |
| 3106 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3107 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3108 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3109 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3110 | case -NFS4ERR_ACCESS: |
| 3111 | if (calldata->arg.bitmask != NULL) { |
| 3112 | calldata->arg.bitmask = NULL; |
| 3113 | calldata->res.fattr = NULL; |
| 3114 | task->tk_status = 0; |
| 3115 | rpc_restart_call_prepare(task); |
| 3116 | goto out_release; |
| 3117 | |
| 3118 | } |
| 3119 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3120 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3122 | case -NFS4ERR_EXPIRED: |
| 3123 | nfs4_free_revoked_stateid(server, |
| 3124 | &calldata->arg.stateid, |
| 3125 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3126 | case -NFS4ERR_OLD_STATEID: |
| 3127 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3128 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3129 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3130 | rpc_restart_call_prepare(task); |
| 3131 | goto out_release; |
| 3132 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3133 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3134 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3136 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3137 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3138 | goto out_release; |
| 3139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3141 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3142 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3143 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3144 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3145 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3146 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3149 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3151 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3152 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3153 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3154 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3155 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3156 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3157 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3158 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3159 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3160 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3161 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3162 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3163 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3164 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3165 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3166 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3167 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3168 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3169 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3170 | if (state->n_rdonly == 0) |
| 3171 | call_close |= is_rdonly; |
| 3172 | else if (is_rdonly) |
| 3173 | calldata->arg.fmode |= FMODE_READ; |
| 3174 | if (state->n_wronly == 0) |
| 3175 | call_close |= is_wronly; |
| 3176 | else if (is_wronly) |
| 3177 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3178 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3179 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3180 | } else if (is_rdwr) |
| 3181 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3182 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3183 | if (!nfs4_valid_open_stateid(state) || |
| 3184 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3185 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3186 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3187 | |
| 3188 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3189 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3190 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3191 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3192 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3193 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3194 | nfs_release_seqid(calldata->arg.seqid); |
| 3195 | goto out_wait; |
| 3196 | } |
| 3197 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3198 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3199 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3200 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3201 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3202 | /* Close-to-open cache consistency revalidation */ |
| 3203 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3204 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3205 | else |
| 3206 | calldata->arg.bitmask = NULL; |
| 3207 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3208 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3209 | calldata->arg.share_access = |
| 3210 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3211 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3212 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3213 | if (calldata->res.fattr == NULL) |
| 3214 | calldata->arg.bitmask = NULL; |
| 3215 | else if (calldata->arg.bitmask == NULL) |
| 3216 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3217 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3218 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3219 | &calldata->arg.seq_args, |
| 3220 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3221 | task) != 0) |
| 3222 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3223 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3224 | return; |
| 3225 | out_no_action: |
| 3226 | task->tk_action = NULL; |
| 3227 | out_wait: |
| 3228 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3231 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3232 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3233 | .rpc_call_done = nfs4_close_done, |
| 3234 | .rpc_release = nfs4_free_closedata, |
| 3235 | }; |
| 3236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | /* |
| 3238 | * It is possible for data to be read/written from a mem-mapped file |
| 3239 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3240 | * This means that we can't safely call nfsv4 close on a file until |
| 3241 | * the inode is cleared. This in turn means that we are not good |
| 3242 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3243 | * share state even when we are done with one of the three share |
| 3244 | * stateid's in the inode. |
| 3245 | * |
| 3246 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3247 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3248 | 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] | 3249 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3250 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3251 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3253 | struct nfs4_state_owner *sp = state->owner; |
| 3254 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3255 | struct rpc_message msg = { |
| 3256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3257 | .rpc_cred = state->owner->so_cred, |
| 3258 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3259 | struct rpc_task_setup task_setup_data = { |
| 3260 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3261 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3262 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3263 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3264 | .flags = RPC_TASK_ASYNC, |
| 3265 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3266 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3268 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3269 | &task_setup_data.rpc_client, &msg); |
| 3270 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3271 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3273 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3274 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3275 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3277 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3279 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3280 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3281 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3282 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3283 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3284 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3285 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3286 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3287 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3288 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3289 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3290 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3291 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3292 | if (calldata->lr.roc) { |
| 3293 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3294 | calldata->res.lr_res = &calldata->lr.res; |
| 3295 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3296 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3297 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3298 | msg.rpc_argp = &calldata->arg; |
| 3299 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3300 | task_setup_data.callback_data = calldata; |
| 3301 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3302 | if (IS_ERR(task)) |
| 3303 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3304 | status = 0; |
| 3305 | if (wait) |
| 3306 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3307 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3308 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3309 | out_free_calldata: |
| 3310 | kfree(calldata); |
| 3311 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3312 | nfs4_put_open_state(state); |
| 3313 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3314 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3317 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3318 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3319 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3322 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3323 | |
| 3324 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3326 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3327 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3328 | |
| 3329 | nfs4_label_release_security(label); |
| 3330 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3331 | if (IS_ERR(state)) |
| 3332 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3333 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3336 | 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] | 3337 | { |
| 3338 | if (ctx->state == NULL) |
| 3339 | return; |
| 3340 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3341 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3342 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3343 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3346 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3347 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3348 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3351 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3352 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3353 | struct nfs4_server_caps_arg args = { |
| 3354 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3355 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3356 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | struct nfs4_server_caps_res res = {}; |
| 3358 | struct rpc_message msg = { |
| 3359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3360 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | .rpc_resp = &res, |
| 3362 | }; |
| 3363 | int status; |
| 3364 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3365 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3366 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3367 | FATTR4_WORD0_LINK_SUPPORT | |
| 3368 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3369 | FATTR4_WORD0_ACLSUPPORT; |
| 3370 | if (minorversion) |
| 3371 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3372 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3373 | 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] | 3374 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3375 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3376 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3377 | case 0: |
| 3378 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3379 | res.attr_bitmask[2] = 0; |
| 3380 | break; |
| 3381 | case 1: |
| 3382 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3383 | break; |
| 3384 | case 2: |
| 3385 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3388 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3389 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3390 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3391 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3392 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3393 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3394 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3395 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | server->caps |= NFS_CAP_ACLS; |
| 3397 | if (res.has_links != 0) |
| 3398 | server->caps |= NFS_CAP_HARDLINKS; |
| 3399 | if (res.has_symlinks != 0) |
| 3400 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3401 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3402 | server->caps |= NFS_CAP_FILEID; |
| 3403 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3404 | server->caps |= NFS_CAP_MODE; |
| 3405 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3406 | server->caps |= NFS_CAP_NLINK; |
| 3407 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3408 | server->caps |= NFS_CAP_OWNER; |
| 3409 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3410 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3411 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3412 | server->caps |= NFS_CAP_ATIME; |
| 3413 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3414 | server->caps |= NFS_CAP_CTIME; |
| 3415 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3416 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3417 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3418 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3419 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3420 | #endif |
| 3421 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3422 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3423 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3424 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3425 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3426 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3427 | 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] | 3428 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3429 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3430 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3432 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | return status; |
| 3436 | } |
| 3437 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3438 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | { |
| 3440 | struct nfs4_exception exception = { }; |
| 3441 | int err; |
| 3442 | do { |
| 3443 | err = nfs4_handle_exception(server, |
| 3444 | _nfs4_server_capabilities(server, fhandle), |
| 3445 | &exception); |
| 3446 | } while (exception.retry); |
| 3447 | return err; |
| 3448 | } |
| 3449 | |
| 3450 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3451 | struct nfs_fsinfo *info) |
| 3452 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3453 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3455 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | }; |
| 3457 | struct nfs4_lookup_res res = { |
| 3458 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3459 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | .fh = fhandle, |
| 3461 | }; |
| 3462 | struct rpc_message msg = { |
| 3463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3464 | .rpc_argp = &args, |
| 3465 | .rpc_resp = &res, |
| 3466 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3467 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3468 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3469 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3470 | /* |
| 3471 | * Process the label in the upcoming getfattr |
| 3472 | */ |
| 3473 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3474 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3475 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3476 | 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] | 3477 | } |
| 3478 | |
| 3479 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3480 | struct nfs_fsinfo *info) |
| 3481 | { |
| 3482 | struct nfs4_exception exception = { }; |
| 3483 | int err; |
| 3484 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3485 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3486 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3487 | switch (err) { |
| 3488 | case 0: |
| 3489 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3490 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3491 | default: |
| 3492 | err = nfs4_handle_exception(server, err, &exception); |
| 3493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3495 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | return err; |
| 3497 | } |
| 3498 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3499 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3500 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3501 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3502 | struct rpc_auth_create_args auth_args = { |
| 3503 | .pseudoflavor = flavor, |
| 3504 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3505 | struct rpc_auth *auth; |
| 3506 | int ret; |
| 3507 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3508 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3509 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3510 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3511 | goto out; |
| 3512 | } |
| 3513 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3514 | out: |
| 3515 | return ret; |
| 3516 | } |
| 3517 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3518 | /* |
| 3519 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3520 | * |
| 3521 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3522 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3523 | * |
| 3524 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3525 | * negative errno value. |
| 3526 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3527 | 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] | 3528 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3530 | /* Per 3530bis 15.33.5 */ |
| 3531 | static const rpc_authflavor_t flav_array[] = { |
| 3532 | RPC_AUTH_GSS_KRB5P, |
| 3533 | RPC_AUTH_GSS_KRB5I, |
| 3534 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3535 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3536 | RPC_AUTH_NULL, |
| 3537 | }; |
| 3538 | int status = -EPERM; |
| 3539 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3541 | if (server->auth_info.flavor_len > 0) { |
| 3542 | /* try each flavor specified by user */ |
| 3543 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3544 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3545 | server->auth_info.flavors[i]); |
| 3546 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3547 | continue; |
| 3548 | break; |
| 3549 | } |
| 3550 | } else { |
| 3551 | /* no flavors specified by user, try default list */ |
| 3552 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3553 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3554 | flav_array[i]); |
| 3555 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3556 | continue; |
| 3557 | break; |
| 3558 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3559 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3560 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3561 | /* |
| 3562 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3563 | * to access the mount. It could also mean that we tried to mount |
| 3564 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3565 | * existing mount programs don't handle -EACCES very well so it should |
| 3566 | * be mapped to -EPERM instead. |
| 3567 | */ |
| 3568 | if (status == -EACCES) |
| 3569 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3570 | return status; |
| 3571 | } |
| 3572 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3573 | /** |
| 3574 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3575 | * @server: initialized nfs_server handle |
| 3576 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3577 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3578 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3579 | * |
| 3580 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3581 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3582 | 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] | 3583 | struct nfs_fsinfo *info, |
| 3584 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3585 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3586 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3587 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3588 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3589 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3590 | |
| 3591 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3592 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3593 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | if (status == 0) |
| 3596 | status = nfs4_server_capabilities(server, fhandle); |
| 3597 | if (status == 0) |
| 3598 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3599 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3600 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3603 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3604 | struct nfs_fsinfo *info) |
| 3605 | { |
| 3606 | int error; |
| 3607 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3609 | |
| 3610 | error = nfs4_server_capabilities(server, mntfh); |
| 3611 | if (error < 0) { |
| 3612 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3613 | return error; |
| 3614 | } |
| 3615 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3616 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3617 | if (IS_ERR(label)) |
| 3618 | return PTR_ERR(label); |
| 3619 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3620 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3621 | if (error < 0) { |
| 3622 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3623 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3627 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3628 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3629 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3630 | err_free_label: |
| 3631 | nfs4_label_free(label); |
| 3632 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3633 | return error; |
| 3634 | } |
| 3635 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3636 | /* |
| 3637 | * Get locations and (maybe) other attributes of a referral. |
| 3638 | * Note that we'll actually follow the referral later when |
| 3639 | * we detect fsid mismatch in inode revalidation |
| 3640 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3641 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3642 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3643 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3644 | { |
| 3645 | int status = -ENOMEM; |
| 3646 | struct page *page = NULL; |
| 3647 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3648 | |
| 3649 | page = alloc_page(GFP_KERNEL); |
| 3650 | if (page == NULL) |
| 3651 | goto out; |
| 3652 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3653 | if (locations == NULL) |
| 3654 | goto out; |
| 3655 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3656 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3657 | if (status != 0) |
| 3658 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3659 | |
| 3660 | /* |
| 3661 | * If the fsid didn't change, this is a migration event, not a |
| 3662 | * referral. Cause us to drop into the exception handler, which |
| 3663 | * will kick off migration recovery. |
| 3664 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3665 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3666 | dprintk("%s: server did not return a different fsid for" |
| 3667 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3668 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3669 | goto out; |
| 3670 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3671 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3672 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3673 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3674 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3675 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3676 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3677 | out: |
| 3678 | if (page) |
| 3679 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3680 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3681 | return status; |
| 3682 | } |
| 3683 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3684 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3685 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | { |
| 3687 | struct nfs4_getattr_arg args = { |
| 3688 | .fh = fhandle, |
| 3689 | .bitmask = server->attr_bitmask, |
| 3690 | }; |
| 3691 | struct nfs4_getattr_res res = { |
| 3692 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3693 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | .server = server, |
| 3695 | }; |
| 3696 | struct rpc_message msg = { |
| 3697 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3698 | .rpc_argp = &args, |
| 3699 | .rpc_resp = &res, |
| 3700 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3701 | |
| 3702 | args.bitmask = nfs4_bitmask(server, label); |
| 3703 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3704 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3705 | 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] | 3706 | } |
| 3707 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3708 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3709 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | { |
| 3711 | struct nfs4_exception exception = { }; |
| 3712 | int err; |
| 3713 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3714 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3715 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3716 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | &exception); |
| 3718 | } while (exception.retry); |
| 3719 | return err; |
| 3720 | } |
| 3721 | |
| 3722 | /* |
| 3723 | * The file is not closed if it is opened due to the a request to change |
| 3724 | * the size of the file. The open call will not be needed once the |
| 3725 | * VFS layer lookup-intents are implemented. |
| 3726 | * |
| 3727 | * Close is called when the inode is destroyed. |
| 3728 | * If we haven't opened the file for O_WRONLY, we |
| 3729 | * need to in the size_change case to obtain a stateid. |
| 3730 | * |
| 3731 | * Got race? |
| 3732 | * Because OPEN is always done by name in nfsv4, it is |
| 3733 | * possible that we opened a different file by the same |
| 3734 | * name. We can recognize this race condition, but we |
| 3735 | * can't do anything about it besides returning an error. |
| 3736 | * |
| 3737 | * This will be fixed with VFS changes (lookup-intent). |
| 3738 | */ |
| 3739 | static int |
| 3740 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3741 | struct iattr *sattr) |
| 3742 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3743 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3744 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3745 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3746 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | int status; |
| 3748 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3749 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3750 | sattr->ia_valid & ATTR_SIZE && |
| 3751 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3752 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3753 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3754 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3756 | /* Deal with open(O_TRUNC) */ |
| 3757 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3758 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3759 | |
| 3760 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3761 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3762 | return 0; |
| 3763 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3764 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3765 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3766 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3767 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3768 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3769 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3770 | } |
| 3771 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3772 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3773 | if (IS_ERR(label)) |
| 3774 | return PTR_ERR(label); |
| 3775 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3776 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3777 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3778 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3779 | nfs_setsecurity(inode, fattr, label); |
| 3780 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3781 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | return status; |
| 3783 | } |
| 3784 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3785 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3786 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3787 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3788 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3789 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3790 | int status; |
| 3791 | struct nfs4_lookup_arg args = { |
| 3792 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3793 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3794 | .name = name, |
| 3795 | }; |
| 3796 | struct nfs4_lookup_res res = { |
| 3797 | .server = server, |
| 3798 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3799 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3800 | .fh = fhandle, |
| 3801 | }; |
| 3802 | struct rpc_message msg = { |
| 3803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3804 | .rpc_argp = &args, |
| 3805 | .rpc_resp = &res, |
| 3806 | }; |
| 3807 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3808 | args.bitmask = nfs4_bitmask(server, label); |
| 3809 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3810 | nfs_fattr_init(fattr); |
| 3811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3813 | 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] | 3814 | dprintk("NFS reply lookup: %d\n", status); |
| 3815 | return status; |
| 3816 | } |
| 3817 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3818 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3819 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3820 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3821 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3822 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3823 | fattr->nlink = 2; |
| 3824 | } |
| 3825 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3826 | 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] | 3827 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3828 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3829 | { |
| 3830 | struct nfs4_exception exception = { }; |
| 3831 | struct rpc_clnt *client = *clnt; |
| 3832 | int err; |
| 3833 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3834 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3835 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3836 | switch (err) { |
| 3837 | case -NFS4ERR_BADNAME: |
| 3838 | err = -ENOENT; |
| 3839 | goto out; |
| 3840 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3841 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3842 | if (err == -NFS4ERR_MOVED) |
| 3843 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3844 | goto out; |
| 3845 | case -NFS4ERR_WRONGSEC: |
| 3846 | err = -EPERM; |
| 3847 | if (client != *clnt) |
| 3848 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3849 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3850 | if (IS_ERR(client)) |
| 3851 | return PTR_ERR(client); |
| 3852 | |
| 3853 | exception.retry = 1; |
| 3854 | break; |
| 3855 | default: |
| 3856 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3857 | } |
| 3858 | } while (exception.retry); |
| 3859 | |
| 3860 | out: |
| 3861 | if (err == 0) |
| 3862 | *clnt = client; |
| 3863 | else if (client != *clnt) |
| 3864 | rpc_shutdown_client(client); |
| 3865 | |
| 3866 | return err; |
| 3867 | } |
| 3868 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3869 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3870 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3871 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3873 | int status; |
| 3874 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3875 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3876 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3877 | if (client != NFS_CLIENT(dir)) { |
| 3878 | rpc_shutdown_client(client); |
| 3879 | nfs_fixup_secinfo_attributes(fattr); |
| 3880 | } |
| 3881 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3884 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3885 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3886 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3887 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3888 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3889 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3890 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3891 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3892 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3893 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3894 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3895 | } |
| 3896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3898 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3899 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | struct nfs4_accessargs args = { |
| 3901 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3902 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3904 | struct nfs4_accessres res = { |
| 3905 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3906 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | struct rpc_message msg = { |
| 3908 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3909 | .rpc_argp = &args, |
| 3910 | .rpc_resp = &res, |
| 3911 | .rpc_cred = entry->cred, |
| 3912 | }; |
| 3913 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3914 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | |
| 3916 | /* |
| 3917 | * Determine which access bits we want to ask for... |
| 3918 | */ |
| 3919 | if (mode & MAY_READ) |
| 3920 | args.access |= NFS4_ACCESS_READ; |
| 3921 | if (S_ISDIR(inode->i_mode)) { |
| 3922 | if (mode & MAY_WRITE) |
| 3923 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3924 | if (mode & MAY_EXEC) |
| 3925 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3926 | } else { |
| 3927 | if (mode & MAY_WRITE) |
| 3928 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3929 | if (mode & MAY_EXEC) |
| 3930 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3931 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3932 | |
| 3933 | res.fattr = nfs_alloc_fattr(); |
| 3934 | if (res.fattr == NULL) |
| 3935 | return -ENOMEM; |
| 3936 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3937 | 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] | 3938 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3939 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3940 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3942 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | return status; |
| 3944 | } |
| 3945 | |
| 3946 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3947 | { |
| 3948 | struct nfs4_exception exception = { }; |
| 3949 | int err; |
| 3950 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3951 | err = _nfs4_proc_access(inode, entry); |
| 3952 | trace_nfs4_access(inode, err); |
| 3953 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | &exception); |
| 3955 | } while (exception.retry); |
| 3956 | return err; |
| 3957 | } |
| 3958 | |
| 3959 | /* |
| 3960 | * TODO: For the time being, we don't try to get any attributes |
| 3961 | * along with any of the zero-copy operations READ, READDIR, |
| 3962 | * READLINK, WRITE. |
| 3963 | * |
| 3964 | * In the case of the first three, we want to put the GETATTR |
| 3965 | * after the read-type operation -- this is because it is hard |
| 3966 | * to predict the length of a GETATTR response in v4, and thus |
| 3967 | * align the READ data correctly. This means that the GETATTR |
| 3968 | * may end up partially falling into the page cache, and we should |
| 3969 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3970 | * To do this efficiently, we need to know the total length |
| 3971 | * of data received, which doesn't seem to be available outside |
| 3972 | * of the RPC layer. |
| 3973 | * |
| 3974 | * In the case of WRITE, we also want to put the GETATTR after |
| 3975 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3976 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | * |
| 3978 | * Both of these changes to the XDR layer would in fact be quite |
| 3979 | * minor, but I decided to leave them for a subsequent patch. |
| 3980 | */ |
| 3981 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3982 | unsigned int pgbase, unsigned int pglen) |
| 3983 | { |
| 3984 | struct nfs4_readlink args = { |
| 3985 | .fh = NFS_FH(inode), |
| 3986 | .pgbase = pgbase, |
| 3987 | .pglen = pglen, |
| 3988 | .pages = &page, |
| 3989 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3990 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | struct rpc_message msg = { |
| 3992 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3993 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3994 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | }; |
| 3996 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3997 | 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] | 3998 | } |
| 3999 | |
| 4000 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4001 | unsigned int pgbase, unsigned int pglen) |
| 4002 | { |
| 4003 | struct nfs4_exception exception = { }; |
| 4004 | int err; |
| 4005 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4006 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4007 | trace_nfs4_readlink(inode, err); |
| 4008 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | &exception); |
| 4010 | } while (exception.retry); |
| 4011 | return err; |
| 4012 | } |
| 4013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4015 | * 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] | 4016 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | static int |
| 4018 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4019 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4021 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4022 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4023 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | int status = 0; |
| 4026 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4027 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4028 | if (IS_ERR(ctx)) |
| 4029 | return PTR_ERR(ctx); |
| 4030 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4031 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4032 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4033 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4034 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4035 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | if (IS_ERR(state)) { |
| 4037 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4038 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4041 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4042 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | return status; |
| 4044 | } |
| 4045 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4046 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4048 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4049 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4051 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4053 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4054 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4055 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4058 | .rpc_argp = &args, |
| 4059 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4061 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4062 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4063 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4064 | 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] | 4065 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4066 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | return status; |
| 4068 | } |
| 4069 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4070 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | { |
| 4072 | struct nfs4_exception exception = { }; |
| 4073 | int err; |
| 4074 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4075 | err = _nfs4_proc_remove(dir, name); |
| 4076 | trace_nfs4_remove(dir, name, err); |
| 4077 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | &exception); |
| 4079 | } while (exception.retry); |
| 4080 | return err; |
| 4081 | } |
| 4082 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4083 | 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] | 4084 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4085 | struct nfs_server *server = NFS_SERVER(dir); |
| 4086 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4087 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4089 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4091 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4092 | |
| 4093 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4096 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4097 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4098 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4099 | &data->args.seq_args, |
| 4100 | &data->res.seq_res, |
| 4101 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4104 | 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] | 4105 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4106 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4107 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4108 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4109 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4110 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4111 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4112 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4113 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4114 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4115 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4116 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4119 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4120 | { |
| 4121 | struct nfs_server *server = NFS_SERVER(dir); |
| 4122 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4123 | struct nfs_renameres *res = msg->rpc_resp; |
| 4124 | |
| 4125 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4126 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4127 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4128 | } |
| 4129 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4130 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4131 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4132 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4133 | &data->args.seq_args, |
| 4134 | &data->res.seq_res, |
| 4135 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4139 | struct inode *new_dir) |
| 4140 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4141 | struct nfs_renamedata *data = task->tk_calldata; |
| 4142 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4143 | |
| 4144 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4145 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4146 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4147 | return 0; |
| 4148 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4149 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4150 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4151 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4152 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4153 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4154 | return 1; |
| 4155 | } |
| 4156 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4157 | 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] | 4158 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4159 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | struct nfs4_link_arg arg = { |
| 4161 | .fh = NFS_FH(inode), |
| 4162 | .dir_fh = NFS_FH(dir), |
| 4163 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4164 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4166 | struct nfs4_link_res res = { |
| 4167 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4168 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4169 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | struct rpc_message msg = { |
| 4171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4172 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4173 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4175 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4177 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4178 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4179 | goto out; |
| 4180 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4181 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4182 | if (IS_ERR(res.label)) { |
| 4183 | status = PTR_ERR(res.label); |
| 4184 | goto out; |
| 4185 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4186 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4187 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4188 | 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] | 4189 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4190 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4191 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4192 | if (!status) |
| 4193 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4194 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4195 | |
| 4196 | |
| 4197 | nfs4_label_free(res.label); |
| 4198 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4199 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4200 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | return status; |
| 4202 | } |
| 4203 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4204 | 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] | 4205 | { |
| 4206 | struct nfs4_exception exception = { }; |
| 4207 | int err; |
| 4208 | do { |
| 4209 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4210 | _nfs4_proc_link(inode, dir, name), |
| 4211 | &exception); |
| 4212 | } while (exception.retry); |
| 4213 | return err; |
| 4214 | } |
| 4215 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4216 | struct nfs4_createdata { |
| 4217 | struct rpc_message msg; |
| 4218 | struct nfs4_create_arg arg; |
| 4219 | struct nfs4_create_res res; |
| 4220 | struct nfs_fh fh; |
| 4221 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4222 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4223 | }; |
| 4224 | |
| 4225 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4226 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4227 | { |
| 4228 | struct nfs4_createdata *data; |
| 4229 | |
| 4230 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4231 | if (data != NULL) { |
| 4232 | struct nfs_server *server = NFS_SERVER(dir); |
| 4233 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4234 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4235 | if (IS_ERR(data->label)) |
| 4236 | goto out_free; |
| 4237 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4238 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4239 | data->msg.rpc_argp = &data->arg; |
| 4240 | data->msg.rpc_resp = &data->res; |
| 4241 | data->arg.dir_fh = NFS_FH(dir); |
| 4242 | data->arg.server = server; |
| 4243 | data->arg.name = name; |
| 4244 | data->arg.attrs = sattr; |
| 4245 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4246 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4247 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4248 | data->res.server = server; |
| 4249 | data->res.fh = &data->fh; |
| 4250 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4251 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4252 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4253 | } |
| 4254 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4255 | out_free: |
| 4256 | kfree(data); |
| 4257 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4261 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4262 | 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] | 4263 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4264 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4265 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4266 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4267 | 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] | 4268 | } |
| 4269 | return status; |
| 4270 | } |
| 4271 | |
| 4272 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4273 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4274 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4275 | kfree(data); |
| 4276 | } |
| 4277 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4278 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4279 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4280 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4282 | struct nfs4_createdata *data; |
| 4283 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4285 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4286 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4287 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4288 | status = -ENOMEM; |
| 4289 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4290 | if (data == NULL) |
| 4291 | goto out; |
| 4292 | |
| 4293 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4294 | data->arg.u.symlink.pages = &page; |
| 4295 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4296 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4298 | status = nfs4_do_create(dir, dentry, data); |
| 4299 | |
| 4300 | nfs4_free_createdata(data); |
| 4301 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | return status; |
| 4303 | } |
| 4304 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4305 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4306 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | { |
| 4308 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4309 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4311 | |
| 4312 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4315 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4316 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4317 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | &exception); |
| 4319 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4320 | |
| 4321 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | return err; |
| 4323 | } |
| 4324 | |
| 4325 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4326 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4328 | struct nfs4_createdata *data; |
| 4329 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4331 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4332 | if (data == NULL) |
| 4333 | goto out; |
| 4334 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4335 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4336 | status = nfs4_do_create(dir, dentry, data); |
| 4337 | |
| 4338 | nfs4_free_createdata(data); |
| 4339 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | return status; |
| 4341 | } |
| 4342 | |
| 4343 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4344 | struct iattr *sattr) |
| 4345 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4346 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4348 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4350 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4351 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4352 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4353 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4354 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4356 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4357 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4358 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | &exception); |
| 4360 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4361 | nfs4_label_release_security(label); |
| 4362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | return err; |
| 4364 | } |
| 4365 | |
| 4366 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4367 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4369 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | struct nfs4_readdir_arg args = { |
| 4371 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4372 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | .pgbase = 0, |
| 4374 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4375 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4376 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | }; |
| 4378 | struct nfs4_readdir_res res; |
| 4379 | struct rpc_message msg = { |
| 4380 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4381 | .rpc_argp = &args, |
| 4382 | .rpc_resp = &res, |
| 4383 | .rpc_cred = cred, |
| 4384 | }; |
| 4385 | int status; |
| 4386 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4387 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4388 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4389 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4390 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4392 | 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] | 4393 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4394 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4395 | status += args.pgbase; |
| 4396 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4397 | |
| 4398 | nfs_invalidate_atime(dir); |
| 4399 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4400 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | return status; |
| 4402 | } |
| 4403 | |
| 4404 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4405 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | { |
| 4407 | struct nfs4_exception exception = { }; |
| 4408 | int err; |
| 4409 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4410 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4411 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4412 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4413 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | &exception); |
| 4415 | } while (exception.retry); |
| 4416 | return err; |
| 4417 | } |
| 4418 | |
| 4419 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4420 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4422 | struct nfs4_createdata *data; |
| 4423 | int mode = sattr->ia_mode; |
| 4424 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4426 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4427 | if (data == NULL) |
| 4428 | goto out; |
| 4429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4431 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4433 | data->arg.ftype = NF4BLK; |
| 4434 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4435 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | } |
| 4437 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4438 | data->arg.ftype = NF4CHR; |
| 4439 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4440 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4441 | } else if (!S_ISSOCK(mode)) { |
| 4442 | status = -EINVAL; |
| 4443 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4445 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4446 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4447 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4448 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4449 | nfs4_free_createdata(data); |
| 4450 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | return status; |
| 4452 | } |
| 4453 | |
| 4454 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4455 | struct iattr *sattr, dev_t rdev) |
| 4456 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4457 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4459 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4461 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4462 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4463 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4464 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4465 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4467 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4468 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4469 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | &exception); |
| 4471 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4472 | |
| 4473 | nfs4_label_release_security(label); |
| 4474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | return err; |
| 4476 | } |
| 4477 | |
| 4478 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4479 | struct nfs_fsstat *fsstat) |
| 4480 | { |
| 4481 | struct nfs4_statfs_arg args = { |
| 4482 | .fh = fhandle, |
| 4483 | .bitmask = server->attr_bitmask, |
| 4484 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4485 | struct nfs4_statfs_res res = { |
| 4486 | .fsstat = fsstat, |
| 4487 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | struct rpc_message msg = { |
| 4489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4490 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4491 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | }; |
| 4493 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4494 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4495 | 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] | 4496 | } |
| 4497 | |
| 4498 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4499 | { |
| 4500 | struct nfs4_exception exception = { }; |
| 4501 | int err; |
| 4502 | do { |
| 4503 | err = nfs4_handle_exception(server, |
| 4504 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4505 | &exception); |
| 4506 | } while (exception.retry); |
| 4507 | return err; |
| 4508 | } |
| 4509 | |
| 4510 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4511 | struct nfs_fsinfo *fsinfo) |
| 4512 | { |
| 4513 | struct nfs4_fsinfo_arg args = { |
| 4514 | .fh = fhandle, |
| 4515 | .bitmask = server->attr_bitmask, |
| 4516 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4517 | struct nfs4_fsinfo_res res = { |
| 4518 | .fsinfo = fsinfo, |
| 4519 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | struct rpc_message msg = { |
| 4521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4522 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4523 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | }; |
| 4525 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4526 | 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] | 4527 | } |
| 4528 | |
| 4529 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4530 | { |
| 4531 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4532 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | int err; |
| 4534 | |
| 4535 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4536 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4537 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4538 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4539 | nfs4_set_lease_period(server->nfs_client, |
| 4540 | fsinfo->lease_time * HZ, |
| 4541 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4542 | break; |
| 4543 | } |
| 4544 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } while (exception.retry); |
| 4546 | return err; |
| 4547 | } |
| 4548 | |
| 4549 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4550 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4551 | int error; |
| 4552 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4553 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4554 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4555 | if (error == 0) { |
| 4556 | /* block layout checks this! */ |
| 4557 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4558 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4559 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4560 | |
| 4561 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4565 | struct nfs_pathconf *pathconf) |
| 4566 | { |
| 4567 | struct nfs4_pathconf_arg args = { |
| 4568 | .fh = fhandle, |
| 4569 | .bitmask = server->attr_bitmask, |
| 4570 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4571 | struct nfs4_pathconf_res res = { |
| 4572 | .pathconf = pathconf, |
| 4573 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | struct rpc_message msg = { |
| 4575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4576 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4577 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | }; |
| 4579 | |
| 4580 | /* None of the pathconf attributes are mandatory to implement */ |
| 4581 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4582 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4583 | return 0; |
| 4584 | } |
| 4585 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4586 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4587 | 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] | 4588 | } |
| 4589 | |
| 4590 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4591 | struct nfs_pathconf *pathconf) |
| 4592 | { |
| 4593 | struct nfs4_exception exception = { }; |
| 4594 | int err; |
| 4595 | |
| 4596 | do { |
| 4597 | err = nfs4_handle_exception(server, |
| 4598 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4599 | &exception); |
| 4600 | } while (exception.retry); |
| 4601 | return err; |
| 4602 | } |
| 4603 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4604 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4605 | const struct nfs_open_context *ctx, |
| 4606 | const struct nfs_lock_context *l_ctx, |
| 4607 | fmode_t fmode) |
| 4608 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4609 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4610 | } |
| 4611 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4612 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4613 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4614 | const struct nfs_open_context *ctx, |
| 4615 | const struct nfs_lock_context *l_ctx, |
| 4616 | fmode_t fmode) |
| 4617 | { |
| 4618 | nfs4_stateid current_stateid; |
| 4619 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4620 | /* If the current stateid represents a lost lock, then exit */ |
| 4621 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4622 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4623 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4624 | } |
| 4625 | |
| 4626 | static bool nfs4_error_stateid_expired(int err) |
| 4627 | { |
| 4628 | switch (err) { |
| 4629 | case -NFS4ERR_DELEG_REVOKED: |
| 4630 | case -NFS4ERR_ADMIN_REVOKED: |
| 4631 | case -NFS4ERR_BAD_STATEID: |
| 4632 | case -NFS4ERR_STALE_STATEID: |
| 4633 | case -NFS4ERR_OLD_STATEID: |
| 4634 | case -NFS4ERR_OPENMODE: |
| 4635 | case -NFS4ERR_EXPIRED: |
| 4636 | return true; |
| 4637 | } |
| 4638 | return false; |
| 4639 | } |
| 4640 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4641 | 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] | 4642 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4643 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4645 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4646 | if (task->tk_status < 0) { |
| 4647 | struct nfs4_exception exception = { |
| 4648 | .inode = hdr->inode, |
| 4649 | .state = hdr->args.context->state, |
| 4650 | .stateid = &hdr->args.stateid, |
| 4651 | }; |
| 4652 | task->tk_status = nfs4_async_handle_exception(task, |
| 4653 | server, task->tk_status, &exception); |
| 4654 | if (exception.retry) { |
| 4655 | rpc_restart_call_prepare(task); |
| 4656 | return -EAGAIN; |
| 4657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4662 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4665 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4666 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4667 | { |
| 4668 | |
| 4669 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4670 | nfs4_stateid_is_current(&args->stateid, |
| 4671 | args->context, |
| 4672 | args->lock_context, |
| 4673 | FMODE_READ)) |
| 4674 | return false; |
| 4675 | rpc_restart_call_prepare(task); |
| 4676 | return true; |
| 4677 | } |
| 4678 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4679 | 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] | 4680 | { |
| 4681 | |
| 4682 | dprintk("--> %s\n", __func__); |
| 4683 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4684 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4685 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4686 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4687 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4688 | if (task->tk_status > 0) |
| 4689 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4690 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4691 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4694 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4695 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4697 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4698 | if (!hdr->pgio_done_cb) |
| 4699 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4700 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4701 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4704 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4705 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4706 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4707 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4708 | &hdr->args.seq_args, |
| 4709 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4710 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4711 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4712 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4713 | hdr->args.lock_context, |
| 4714 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4715 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4716 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4717 | return -EIO; |
| 4718 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4721 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4722 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4724 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4725 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4726 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4727 | if (task->tk_status < 0) { |
| 4728 | struct nfs4_exception exception = { |
| 4729 | .inode = hdr->inode, |
| 4730 | .state = hdr->args.context->state, |
| 4731 | .stateid = &hdr->args.stateid, |
| 4732 | }; |
| 4733 | task->tk_status = nfs4_async_handle_exception(task, |
| 4734 | NFS_SERVER(inode), task->tk_status, |
| 4735 | &exception); |
| 4736 | if (exception.retry) { |
| 4737 | rpc_restart_call_prepare(task); |
| 4738 | return -EAGAIN; |
| 4739 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4741 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4742 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4743 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4744 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4745 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4748 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4749 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4750 | { |
| 4751 | |
| 4752 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4753 | nfs4_stateid_is_current(&args->stateid, |
| 4754 | args->context, |
| 4755 | args->lock_context, |
| 4756 | FMODE_WRITE)) |
| 4757 | return false; |
| 4758 | rpc_restart_call_prepare(task); |
| 4759 | return true; |
| 4760 | } |
| 4761 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4762 | 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] | 4763 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4764 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4765 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4766 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4767 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4768 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4769 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4770 | } |
| 4771 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4772 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4773 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4774 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4775 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4776 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4777 | return false; |
| 4778 | /* Otherwise, request attributes if and only if we don't hold |
| 4779 | * a delegation |
| 4780 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4781 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4782 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4783 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4784 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4785 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4787 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4788 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4789 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4790 | hdr->args.bitmask = NULL; |
| 4791 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4792 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4793 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4794 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4795 | if (!hdr->pgio_done_cb) |
| 4796 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4797 | hdr->res.server = server; |
| 4798 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4800 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4801 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4804 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4805 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4806 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4807 | &data->args.seq_args, |
| 4808 | &data->res.seq_res, |
| 4809 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4812 | 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] | 4813 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4815 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4816 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4817 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4818 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4819 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4820 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4822 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4825 | 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] | 4826 | { |
| 4827 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4828 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4829 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4832 | 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] | 4833 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4834 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4835 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4836 | if (data->commit_done_cb == NULL) |
| 4837 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4838 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4839 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4840 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4843 | struct nfs4_renewdata { |
| 4844 | struct nfs_client *client; |
| 4845 | unsigned long timestamp; |
| 4846 | }; |
| 4847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | /* |
| 4849 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4850 | * standalone procedure for queueing an asynchronous RENEW. |
| 4851 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4852 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4853 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4854 | struct nfs4_renewdata *data = calldata; |
| 4855 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4856 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4857 | if (atomic_read(&clp->cl_count) > 1) |
| 4858 | nfs4_schedule_state_renewal(clp); |
| 4859 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4860 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4861 | } |
| 4862 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4863 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4865 | struct nfs4_renewdata *data = calldata; |
| 4866 | struct nfs_client *clp = data->client; |
| 4867 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4869 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4870 | switch (task->tk_status) { |
| 4871 | case 0: |
| 4872 | break; |
| 4873 | case -NFS4ERR_LEASE_MOVED: |
| 4874 | nfs4_schedule_lease_moved_recovery(clp); |
| 4875 | break; |
| 4876 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4877 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4878 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4879 | return; |
| 4880 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4881 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4882 | return; |
| 4883 | } |
| 4884 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4886 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4889 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4890 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4891 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4892 | }; |
| 4893 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4894 | 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] | 4895 | { |
| 4896 | struct rpc_message msg = { |
| 4897 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4898 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4899 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4901 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4903 | if (renew_flags == 0) |
| 4904 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4905 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4906 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4907 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4908 | if (data == NULL) |
| 4909 | return -ENOMEM; |
| 4910 | data->client = clp; |
| 4911 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4912 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4913 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4916 | 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] | 4917 | { |
| 4918 | struct rpc_message msg = { |
| 4919 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4920 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4921 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | }; |
| 4923 | unsigned long now = jiffies; |
| 4924 | int status; |
| 4925 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4926 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | if (status < 0) |
| 4928 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4929 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | return 0; |
| 4931 | } |
| 4932 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4933 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4934 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4935 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4938 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4939 | * 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] | 4940 | * the stack. |
| 4941 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4942 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4943 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4944 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4945 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4946 | { |
| 4947 | struct page *newpage, **spages; |
| 4948 | int rc = 0; |
| 4949 | size_t len; |
| 4950 | spages = pages; |
| 4951 | |
| 4952 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4953 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4954 | newpage = alloc_page(GFP_KERNEL); |
| 4955 | |
| 4956 | if (newpage == NULL) |
| 4957 | goto unwind; |
| 4958 | memcpy(page_address(newpage), buf, len); |
| 4959 | buf += len; |
| 4960 | buflen -= len; |
| 4961 | *pages++ = newpage; |
| 4962 | rc++; |
| 4963 | } while (buflen != 0); |
| 4964 | |
| 4965 | return rc; |
| 4966 | |
| 4967 | unwind: |
| 4968 | for(; rc > 0; rc--) |
| 4969 | __free_page(spages[rc-1]); |
| 4970 | return -ENOMEM; |
| 4971 | } |
| 4972 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4973 | struct nfs4_cached_acl { |
| 4974 | int cached; |
| 4975 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4976 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4977 | }; |
| 4978 | |
| 4979 | 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] | 4980 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4981 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4982 | |
| 4983 | spin_lock(&inode->i_lock); |
| 4984 | kfree(nfsi->nfs4_acl); |
| 4985 | nfsi->nfs4_acl = acl; |
| 4986 | spin_unlock(&inode->i_lock); |
| 4987 | } |
| 4988 | |
| 4989 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4990 | { |
| 4991 | nfs4_set_cached_acl(inode, NULL); |
| 4992 | } |
| 4993 | |
| 4994 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4995 | { |
| 4996 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4997 | struct nfs4_cached_acl *acl; |
| 4998 | int ret = -ENOENT; |
| 4999 | |
| 5000 | spin_lock(&inode->i_lock); |
| 5001 | acl = nfsi->nfs4_acl; |
| 5002 | if (acl == NULL) |
| 5003 | goto out; |
| 5004 | if (buf == NULL) /* user is just asking for length */ |
| 5005 | goto out_len; |
| 5006 | if (acl->cached == 0) |
| 5007 | goto out; |
| 5008 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5009 | if (acl->len > buflen) |
| 5010 | goto out; |
| 5011 | memcpy(buf, acl->data, acl->len); |
| 5012 | out_len: |
| 5013 | ret = acl->len; |
| 5014 | out: |
| 5015 | spin_unlock(&inode->i_lock); |
| 5016 | return ret; |
| 5017 | } |
| 5018 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5019 | 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] | 5020 | { |
| 5021 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5022 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5023 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5024 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5025 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5026 | if (acl == NULL) |
| 5027 | goto out; |
| 5028 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5029 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5030 | } else { |
| 5031 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5032 | if (acl == NULL) |
| 5033 | goto out; |
| 5034 | acl->cached = 0; |
| 5035 | } |
| 5036 | acl->len = acl_len; |
| 5037 | out: |
| 5038 | nfs4_set_cached_acl(inode, acl); |
| 5039 | } |
| 5040 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5041 | /* |
| 5042 | * The getxattr API returns the required buffer length when called with a |
| 5043 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5044 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5045 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5046 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5047 | * the cache. If not so, we throw away the page, and cache the required |
| 5048 | * length. The next getxattr call will then produce another round trip to |
| 5049 | * the server, this time with the input buf of the required size. |
| 5050 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5051 | 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] | 5052 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5053 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5054 | struct nfs_getaclargs args = { |
| 5055 | .fh = NFS_FH(inode), |
| 5056 | .acl_pages = pages, |
| 5057 | .acl_len = buflen, |
| 5058 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5059 | struct nfs_getaclres res = { |
| 5060 | .acl_len = buflen, |
| 5061 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5062 | struct rpc_message msg = { |
| 5063 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5064 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5065 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5066 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5067 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5068 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5069 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5070 | /* As long as we're doing a round trip to the server anyway, |
| 5071 | * let's be prepared for a page of acl data. */ |
| 5072 | if (npages == 0) |
| 5073 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5074 | if (npages > ARRAY_SIZE(pages)) |
| 5075 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5076 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5077 | for (i = 0; i < npages; i++) { |
| 5078 | pages[i] = alloc_page(GFP_KERNEL); |
| 5079 | if (!pages[i]) |
| 5080 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5081 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5082 | |
| 5083 | /* for decoding across pages */ |
| 5084 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5085 | if (!res.acl_scratch) |
| 5086 | goto out_free; |
| 5087 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5088 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5089 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5090 | 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] | 5091 | __func__, buf, buflen, npages, args.acl_len); |
| 5092 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5093 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5094 | if (ret) |
| 5095 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5096 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5097 | /* Handle the case where the passed-in buffer is too short */ |
| 5098 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5099 | /* Did the user only issue a request for the acl length? */ |
| 5100 | if (buf == NULL) |
| 5101 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5102 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5103 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5104 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5105 | 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] | 5106 | if (buf) { |
| 5107 | if (res.acl_len > buflen) { |
| 5108 | ret = -ERANGE; |
| 5109 | goto out_free; |
| 5110 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5111 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5112 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5113 | out_ok: |
| 5114 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5115 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5116 | for (i = 0; i < npages; i++) |
| 5117 | if (pages[i]) |
| 5118 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5119 | if (res.acl_scratch) |
| 5120 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5121 | return ret; |
| 5122 | } |
| 5123 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5124 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5125 | { |
| 5126 | struct nfs4_exception exception = { }; |
| 5127 | ssize_t ret; |
| 5128 | do { |
| 5129 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5130 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5131 | if (ret >= 0) |
| 5132 | break; |
| 5133 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5134 | } while (exception.retry); |
| 5135 | return ret; |
| 5136 | } |
| 5137 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5138 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5139 | { |
| 5140 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5141 | int ret; |
| 5142 | |
| 5143 | if (!nfs4_server_supports_acls(server)) |
| 5144 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5145 | ret = nfs_revalidate_inode(server, inode); |
| 5146 | if (ret < 0) |
| 5147 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5148 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5149 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5150 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5151 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5152 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5153 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5154 | return ret; |
| 5155 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5156 | } |
| 5157 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5158 | 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] | 5159 | { |
| 5160 | struct nfs_server *server = NFS_SERVER(inode); |
| 5161 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5162 | struct nfs_setaclargs arg = { |
| 5163 | .fh = NFS_FH(inode), |
| 5164 | .acl_pages = pages, |
| 5165 | .acl_len = buflen, |
| 5166 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5167 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5168 | struct rpc_message msg = { |
| 5169 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5170 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5171 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5172 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5173 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5174 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5175 | |
| 5176 | if (!nfs4_server_supports_acls(server)) |
| 5177 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5178 | if (npages > ARRAY_SIZE(pages)) |
| 5179 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5180 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5181 | if (i < 0) |
| 5182 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5183 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5184 | 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] | 5185 | |
| 5186 | /* |
| 5187 | * Free each page after tx, so the only ref left is |
| 5188 | * held by the network stack |
| 5189 | */ |
| 5190 | for (; i > 0; i--) |
| 5191 | put_page(pages[i-1]); |
| 5192 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5193 | /* |
| 5194 | * Acl update can result in inode attribute update. |
| 5195 | * so mark the attribute cache invalid. |
| 5196 | */ |
| 5197 | spin_lock(&inode->i_lock); |
| 5198 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5199 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5200 | nfs_access_zap_cache(inode); |
| 5201 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5202 | return ret; |
| 5203 | } |
| 5204 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5205 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5206 | { |
| 5207 | struct nfs4_exception exception = { }; |
| 5208 | int err; |
| 5209 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5210 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5211 | trace_nfs4_set_acl(inode, err); |
| 5212 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5213 | &exception); |
| 5214 | } while (exception.retry); |
| 5215 | return err; |
| 5216 | } |
| 5217 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5218 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5219 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5220 | size_t buflen) |
| 5221 | { |
| 5222 | struct nfs_server *server = NFS_SERVER(inode); |
| 5223 | struct nfs_fattr fattr; |
| 5224 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5225 | |
| 5226 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5227 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5228 | .fh = NFS_FH(inode), |
| 5229 | .bitmask = bitmask, |
| 5230 | }; |
| 5231 | struct nfs4_getattr_res res = { |
| 5232 | .fattr = &fattr, |
| 5233 | .label = &label, |
| 5234 | .server = server, |
| 5235 | }; |
| 5236 | struct rpc_message msg = { |
| 5237 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5238 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5239 | .rpc_resp = &res, |
| 5240 | }; |
| 5241 | int ret; |
| 5242 | |
| 5243 | nfs_fattr_init(&fattr); |
| 5244 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5245 | 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] | 5246 | if (ret) |
| 5247 | return ret; |
| 5248 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5249 | return -ENOENT; |
| 5250 | if (buflen < label.len) |
| 5251 | return -ERANGE; |
| 5252 | return 0; |
| 5253 | } |
| 5254 | |
| 5255 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5256 | size_t buflen) |
| 5257 | { |
| 5258 | struct nfs4_exception exception = { }; |
| 5259 | int err; |
| 5260 | |
| 5261 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5262 | return -EOPNOTSUPP; |
| 5263 | |
| 5264 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5265 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5266 | trace_nfs4_get_security_label(inode, err); |
| 5267 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5268 | &exception); |
| 5269 | } while (exception.retry); |
| 5270 | return err; |
| 5271 | } |
| 5272 | |
| 5273 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5274 | struct nfs4_label *ilabel, |
| 5275 | struct nfs_fattr *fattr, |
| 5276 | struct nfs4_label *olabel) |
| 5277 | { |
| 5278 | |
| 5279 | struct iattr sattr = {0}; |
| 5280 | struct nfs_server *server = NFS_SERVER(inode); |
| 5281 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5282 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5283 | .fh = NFS_FH(inode), |
| 5284 | .iap = &sattr, |
| 5285 | .server = server, |
| 5286 | .bitmask = bitmask, |
| 5287 | .label = ilabel, |
| 5288 | }; |
| 5289 | struct nfs_setattrres res = { |
| 5290 | .fattr = fattr, |
| 5291 | .label = olabel, |
| 5292 | .server = server, |
| 5293 | }; |
| 5294 | struct rpc_message msg = { |
| 5295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5296 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5297 | .rpc_resp = &res, |
| 5298 | }; |
| 5299 | int status; |
| 5300 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5301 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5302 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5303 | 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] | 5304 | if (status) |
| 5305 | dprintk("%s failed: %d\n", __func__, status); |
| 5306 | |
| 5307 | return status; |
| 5308 | } |
| 5309 | |
| 5310 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5311 | struct nfs4_label *ilabel, |
| 5312 | struct nfs_fattr *fattr, |
| 5313 | struct nfs4_label *olabel) |
| 5314 | { |
| 5315 | struct nfs4_exception exception = { }; |
| 5316 | int err; |
| 5317 | |
| 5318 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5319 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5320 | fattr, olabel); |
| 5321 | trace_nfs4_set_security_label(inode, err); |
| 5322 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5323 | &exception); |
| 5324 | } while (exception.retry); |
| 5325 | return err; |
| 5326 | } |
| 5327 | |
| 5328 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5329 | 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] | 5330 | { |
| 5331 | struct nfs4_label ilabel, *olabel = NULL; |
| 5332 | struct nfs_fattr fattr; |
| 5333 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5334 | int status; |
| 5335 | |
| 5336 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5337 | return -EOPNOTSUPP; |
| 5338 | |
| 5339 | nfs_fattr_init(&fattr); |
| 5340 | |
| 5341 | ilabel.pi = 0; |
| 5342 | ilabel.lfs = 0; |
| 5343 | ilabel.label = (char *)buf; |
| 5344 | ilabel.len = buflen; |
| 5345 | |
| 5346 | cred = rpc_lookup_cred(); |
| 5347 | if (IS_ERR(cred)) |
| 5348 | return PTR_ERR(cred); |
| 5349 | |
| 5350 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5351 | if (IS_ERR(olabel)) { |
| 5352 | status = -PTR_ERR(olabel); |
| 5353 | goto out; |
| 5354 | } |
| 5355 | |
| 5356 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5357 | if (status == 0) |
| 5358 | nfs_setsecurity(inode, &fattr, olabel); |
| 5359 | |
| 5360 | nfs4_label_free(olabel); |
| 5361 | out: |
| 5362 | put_rpccred(cred); |
| 5363 | return status; |
| 5364 | } |
| 5365 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5366 | |
| 5367 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5368 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5369 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5370 | { |
| 5371 | __be32 verf[2]; |
| 5372 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5373 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5374 | /* An impossible timestamp guarantees this value |
| 5375 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5376 | verf[0] = cpu_to_be32(U32_MAX); |
| 5377 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5378 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5379 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5380 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5381 | |
| 5382 | verf[0] = cpu_to_be32(ns >> 32); |
| 5383 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5384 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5385 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5386 | } |
| 5387 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5388 | static int |
| 5389 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5390 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5391 | size_t len; |
| 5392 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5393 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5394 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5395 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5396 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5397 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5398 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5399 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5400 | 1 + |
| 5401 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5402 | 1; |
| 5403 | rcu_read_unlock(); |
| 5404 | |
| 5405 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5406 | return -EINVAL; |
| 5407 | |
| 5408 | /* |
| 5409 | * Since this string is allocated at mount time, and held until the |
| 5410 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5411 | * about a memory-reclaim deadlock. |
| 5412 | */ |
| 5413 | str = kmalloc(len, GFP_KERNEL); |
| 5414 | if (!str) |
| 5415 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5416 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5417 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5418 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5419 | clp->cl_ipaddr, |
| 5420 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5421 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5422 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5423 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5424 | clp->cl_owner_id = str; |
| 5425 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5426 | } |
| 5427 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5428 | static int |
| 5429 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5430 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5431 | size_t len; |
| 5432 | char *str; |
| 5433 | |
| 5434 | len = 10 + 10 + 1 + 10 + 1 + |
| 5435 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5436 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5437 | |
| 5438 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5439 | return -EINVAL; |
| 5440 | |
| 5441 | /* |
| 5442 | * Since this string is allocated at mount time, and held until the |
| 5443 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5444 | * about a memory-reclaim deadlock. |
| 5445 | */ |
| 5446 | str = kmalloc(len, GFP_KERNEL); |
| 5447 | if (!str) |
| 5448 | return -ENOMEM; |
| 5449 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5450 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5451 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5452 | nfs4_client_id_uniquifier, |
| 5453 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5454 | clp->cl_owner_id = str; |
| 5455 | return 0; |
| 5456 | } |
| 5457 | |
| 5458 | static int |
| 5459 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5460 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5461 | size_t len; |
| 5462 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5463 | |
| 5464 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5465 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5466 | |
| 5467 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5468 | return nfs4_init_uniquifier_client_string(clp); |
| 5469 | |
| 5470 | len = 10 + 10 + 1 + 10 + 1 + |
| 5471 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5472 | |
| 5473 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5474 | return -EINVAL; |
| 5475 | |
| 5476 | /* |
| 5477 | * Since this string is allocated at mount time, and held until the |
| 5478 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5479 | * about a memory-reclaim deadlock. |
| 5480 | */ |
| 5481 | str = kmalloc(len, GFP_KERNEL); |
| 5482 | if (!str) |
| 5483 | return -ENOMEM; |
| 5484 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5485 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5486 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5487 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5488 | clp->cl_owner_id = str; |
| 5489 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5490 | } |
| 5491 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5492 | /* |
| 5493 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5494 | * services. Advertise one based on the address family of the |
| 5495 | * clientaddr. |
| 5496 | */ |
| 5497 | static unsigned int |
| 5498 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5499 | { |
| 5500 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5501 | return scnprintf(buf, len, "tcp6"); |
| 5502 | else |
| 5503 | return scnprintf(buf, len, "tcp"); |
| 5504 | } |
| 5505 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5506 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5507 | { |
| 5508 | struct nfs4_setclientid *sc = calldata; |
| 5509 | |
| 5510 | if (task->tk_status == 0) |
| 5511 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5512 | } |
| 5513 | |
| 5514 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5515 | .rpc_call_done = nfs4_setclientid_done, |
| 5516 | }; |
| 5517 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5518 | /** |
| 5519 | * nfs4_proc_setclientid - Negotiate client ID |
| 5520 | * @clp: state data structure |
| 5521 | * @program: RPC program for NFSv4 callback service |
| 5522 | * @port: IP port number for NFS4 callback service |
| 5523 | * @cred: RPC credential to use for this call |
| 5524 | * @res: where to place the result |
| 5525 | * |
| 5526 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5527 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5528 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5529 | unsigned short port, struct rpc_cred *cred, |
| 5530 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | { |
| 5532 | nfs4_verifier sc_verifier; |
| 5533 | struct nfs4_setclientid setclientid = { |
| 5534 | .sc_verifier = &sc_verifier, |
| 5535 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5536 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | }; |
| 5538 | struct rpc_message msg = { |
| 5539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5540 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5541 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5542 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5544 | struct rpc_task *task; |
| 5545 | struct rpc_task_setup task_setup_data = { |
| 5546 | .rpc_client = clp->cl_rpcclient, |
| 5547 | .rpc_message = &msg, |
| 5548 | .callback_ops = &nfs4_setclientid_ops, |
| 5549 | .callback_data = &setclientid, |
| 5550 | .flags = RPC_TASK_TIMEOUT, |
| 5551 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5552 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5554 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5555 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5556 | |
| 5557 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5558 | status = nfs4_init_uniform_client_string(clp); |
| 5559 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5560 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5561 | |
| 5562 | if (status) |
| 5563 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5564 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5565 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5566 | setclientid.sc_netid_len = |
| 5567 | nfs4_init_callback_netid(clp, |
| 5568 | setclientid.sc_netid, |
| 5569 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5570 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5571 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5573 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5574 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5575 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5576 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5577 | task = rpc_run_task(&task_setup_data); |
| 5578 | if (IS_ERR(task)) { |
| 5579 | status = PTR_ERR(task); |
| 5580 | goto out; |
| 5581 | } |
| 5582 | status = task->tk_status; |
| 5583 | if (setclientid.sc_cred) { |
| 5584 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5585 | put_rpccred(setclientid.sc_cred); |
| 5586 | } |
| 5587 | rpc_put_task(task); |
| 5588 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5589 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5590 | dprintk("NFS reply setclientid: %d\n", status); |
| 5591 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5594 | /** |
| 5595 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5596 | * @clp: state data structure |
| 5597 | * @res: result of a previous SETCLIENTID |
| 5598 | * @cred: RPC credential to use for this call |
| 5599 | * |
| 5600 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5601 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5602 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5603 | struct nfs4_setclientid_res *arg, |
| 5604 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | struct rpc_message msg = { |
| 5607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5608 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5609 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | int status; |
| 5612 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5613 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5614 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5615 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5616 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5617 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5618 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | return status; |
| 5620 | } |
| 5621 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5622 | struct nfs4_delegreturndata { |
| 5623 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5624 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5625 | struct nfs_fh fh; |
| 5626 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5627 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5628 | struct { |
| 5629 | struct nfs4_layoutreturn_args arg; |
| 5630 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5631 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5632 | u32 roc_barrier; |
| 5633 | bool roc; |
| 5634 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5635 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5636 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5637 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5638 | }; |
| 5639 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5640 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5641 | { |
| 5642 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5643 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5644 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5645 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5646 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5647 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5648 | |
| 5649 | /* Handle Layoutreturn errors */ |
| 5650 | if (data->args.lr_args && task->tk_status != 0) { |
| 5651 | switch(data->res.lr_ret) { |
| 5652 | default: |
| 5653 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5654 | break; |
| 5655 | case 0: |
| 5656 | data->args.lr_args = NULL; |
| 5657 | data->res.lr_res = NULL; |
| 5658 | break; |
| 5659 | case -NFS4ERR_ADMIN_REVOKED: |
| 5660 | case -NFS4ERR_DELEG_REVOKED: |
| 5661 | case -NFS4ERR_EXPIRED: |
| 5662 | case -NFS4ERR_BAD_STATEID: |
| 5663 | case -NFS4ERR_OLD_STATEID: |
| 5664 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5665 | case -NFS4ERR_WRONG_CRED: |
| 5666 | data->args.lr_args = NULL; |
| 5667 | data->res.lr_res = NULL; |
| 5668 | data->res.lr_ret = 0; |
| 5669 | rpc_restart_call_prepare(task); |
| 5670 | return; |
| 5671 | } |
| 5672 | } |
| 5673 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5674 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5675 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5676 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5677 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5678 | case -NFS4ERR_ADMIN_REVOKED: |
| 5679 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5680 | case -NFS4ERR_EXPIRED: |
| 5681 | nfs4_free_revoked_stateid(data->res.server, |
| 5682 | data->args.stateid, |
| 5683 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5684 | case -NFS4ERR_BAD_STATEID: |
| 5685 | case -NFS4ERR_OLD_STATEID: |
| 5686 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5687 | task->tk_status = 0; |
| 5688 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5689 | case -NFS4ERR_ACCESS: |
| 5690 | if (data->args.bitmask) { |
| 5691 | data->args.bitmask = NULL; |
| 5692 | data->res.fattr = NULL; |
| 5693 | task->tk_status = 0; |
| 5694 | rpc_restart_call_prepare(task); |
| 5695 | return; |
| 5696 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5697 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5698 | if (nfs4_async_handle_error(task, data->res.server, |
| 5699 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5700 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5701 | return; |
| 5702 | } |
| 5703 | } |
| 5704 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5705 | } |
| 5706 | |
| 5707 | static void nfs4_delegreturn_release(void *calldata) |
| 5708 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5709 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5710 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5711 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5712 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5713 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5714 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5715 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5716 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5717 | nfs_iput_and_deactive(inode); |
| 5718 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5719 | kfree(calldata); |
| 5720 | } |
| 5721 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5722 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5723 | { |
| 5724 | struct nfs4_delegreturndata *d_data; |
| 5725 | |
| 5726 | d_data = (struct nfs4_delegreturndata *)data; |
| 5727 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5728 | 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] | 5729 | return; |
| 5730 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5731 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5732 | &d_data->args.seq_args, |
| 5733 | &d_data->res.seq_res, |
| 5734 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5735 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5736 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5737 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5738 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5739 | .rpc_call_done = nfs4_delegreturn_done, |
| 5740 | .rpc_release = nfs4_delegreturn_release, |
| 5741 | }; |
| 5742 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5743 | 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] | 5744 | { |
| 5745 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5746 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5747 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5748 | struct rpc_message msg = { |
| 5749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5750 | .rpc_cred = cred, |
| 5751 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5752 | struct rpc_task_setup task_setup_data = { |
| 5753 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5754 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5755 | .callback_ops = &nfs4_delegreturn_ops, |
| 5756 | .flags = RPC_TASK_ASYNC, |
| 5757 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5758 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5759 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5760 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5761 | if (data == NULL) |
| 5762 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5763 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5764 | |
| 5765 | nfs4_state_protect(server->nfs_client, |
| 5766 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5767 | &task_setup_data.rpc_client, &msg); |
| 5768 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5769 | data->args.fhandle = &data->fh; |
| 5770 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5771 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5772 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5773 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5774 | data->res.fattr = &data->fattr; |
| 5775 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5776 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5777 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5778 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5779 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5780 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5781 | 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] | 5782 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5783 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5784 | if (data->lr.roc) { |
| 5785 | data->args.lr_args = &data->lr.arg; |
| 5786 | data->res.lr_res = &data->lr.res; |
| 5787 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5788 | } else if (data->lr.roc) { |
| 5789 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5790 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5791 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5792 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5793 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5794 | msg.rpc_argp = &data->args; |
| 5795 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5796 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5797 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5798 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5799 | if (!issync) |
| 5800 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5801 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5802 | if (status != 0) |
| 5803 | goto out; |
| 5804 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5805 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5806 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5807 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | } |
| 5809 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5810 | 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] | 5811 | { |
| 5812 | struct nfs_server *server = NFS_SERVER(inode); |
| 5813 | struct nfs4_exception exception = { }; |
| 5814 | int err; |
| 5815 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5816 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5817 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | switch (err) { |
| 5819 | case -NFS4ERR_STALE_STATEID: |
| 5820 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | case 0: |
| 5822 | return 0; |
| 5823 | } |
| 5824 | err = nfs4_handle_exception(server, err, &exception); |
| 5825 | } while (exception.retry); |
| 5826 | return err; |
| 5827 | } |
| 5828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5830 | { |
| 5831 | struct inode *inode = state->inode; |
| 5832 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5833 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5834 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5836 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5838 | struct nfs_lockt_res res = { |
| 5839 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | }; |
| 5841 | struct rpc_message msg = { |
| 5842 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5843 | .rpc_argp = &arg, |
| 5844 | .rpc_resp = &res, |
| 5845 | .rpc_cred = state->owner->so_cred, |
| 5846 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | struct nfs4_lock_state *lsp; |
| 5848 | int status; |
| 5849 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5850 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5851 | status = nfs4_set_lock_state(state, request); |
| 5852 | if (status != 0) |
| 5853 | goto out; |
| 5854 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5855 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5856 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5857 | 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] | 5858 | switch (status) { |
| 5859 | case 0: |
| 5860 | request->fl_type = F_UNLCK; |
| 5861 | break; |
| 5862 | case -NFS4ERR_DENIED: |
| 5863 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5865 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5866 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5867 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | return status; |
| 5869 | } |
| 5870 | |
| 5871 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5872 | { |
| 5873 | struct nfs4_exception exception = { }; |
| 5874 | int err; |
| 5875 | |
| 5876 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5877 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5878 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5879 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | &exception); |
| 5881 | } while (exception.retry); |
| 5882 | return err; |
| 5883 | } |
| 5884 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5885 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5886 | struct nfs_locku_args arg; |
| 5887 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5888 | struct nfs4_lock_state *lsp; |
| 5889 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5890 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5891 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5892 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5893 | }; |
| 5894 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5895 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5896 | struct nfs_open_context *ctx, |
| 5897 | struct nfs4_lock_state *lsp, |
| 5898 | struct nfs_seqid *seqid) |
| 5899 | { |
| 5900 | struct nfs4_unlockdata *p; |
| 5901 | struct inode *inode = lsp->ls_state->inode; |
| 5902 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5903 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5904 | if (p == NULL) |
| 5905 | return NULL; |
| 5906 | p->arg.fh = NFS_FH(inode); |
| 5907 | p->arg.fl = &p->fl; |
| 5908 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5909 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5910 | p->lsp = lsp; |
| 5911 | atomic_inc(&lsp->ls_count); |
| 5912 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5913 | p->ctx = get_nfs_open_context(ctx); |
| 5914 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5915 | p->server = NFS_SERVER(inode); |
| 5916 | return p; |
| 5917 | } |
| 5918 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5919 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5920 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5921 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5922 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5923 | nfs4_put_lock_state(calldata->lsp); |
| 5924 | put_nfs_open_context(calldata->ctx); |
| 5925 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5928 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5929 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5930 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5931 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5932 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5933 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5934 | switch (task->tk_status) { |
| 5935 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5936 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5937 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5938 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5939 | &calldata->res.stateid)) |
| 5940 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5941 | case -NFS4ERR_ADMIN_REVOKED: |
| 5942 | case -NFS4ERR_EXPIRED: |
| 5943 | nfs4_free_revoked_stateid(calldata->server, |
| 5944 | &calldata->arg.stateid, |
| 5945 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5946 | case -NFS4ERR_BAD_STATEID: |
| 5947 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5948 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5949 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5950 | &calldata->lsp->ls_stateid)) |
| 5951 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5952 | break; |
| 5953 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5954 | if (nfs4_async_handle_error(task, calldata->server, |
| 5955 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5956 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5957 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5958 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5961 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5962 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5963 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5965 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5966 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5967 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5968 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5969 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5970 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5971 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5972 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5973 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5974 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5975 | &calldata->res.seq_res, |
| 5976 | task) != 0) |
| 5977 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5978 | return; |
| 5979 | out_no_action: |
| 5980 | task->tk_action = NULL; |
| 5981 | out_wait: |
| 5982 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5985 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5986 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5987 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5988 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5989 | }; |
| 5990 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5991 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5992 | struct nfs_open_context *ctx, |
| 5993 | struct nfs4_lock_state *lsp, |
| 5994 | struct nfs_seqid *seqid) |
| 5995 | { |
| 5996 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5997 | struct rpc_message msg = { |
| 5998 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5999 | .rpc_cred = ctx->cred, |
| 6000 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6001 | struct rpc_task_setup task_setup_data = { |
| 6002 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6003 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6004 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6005 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6006 | .flags = RPC_TASK_ASYNC, |
| 6007 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6008 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6009 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6010 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6011 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6012 | /* Ensure this is an unlock - when canceling a lock, the |
| 6013 | * canceled lock is passed in, and it won't be an unlock. |
| 6014 | */ |
| 6015 | fl->fl_type = F_UNLCK; |
| 6016 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6017 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6018 | if (data == NULL) { |
| 6019 | nfs_free_seqid(seqid); |
| 6020 | return ERR_PTR(-ENOMEM); |
| 6021 | } |
| 6022 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6023 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6024 | msg.rpc_argp = &data->arg; |
| 6025 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6026 | task_setup_data.callback_data = data; |
| 6027 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6028 | } |
| 6029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6031 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6032 | struct inode *inode = state->inode; |
| 6033 | struct nfs4_state_owner *sp = state->owner; |
| 6034 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6035 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6036 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6037 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6038 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6039 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6040 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6041 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6042 | status = nfs4_set_lock_state(state, request); |
| 6043 | /* Unlock _before_ we do the RPC call */ |
| 6044 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6045 | /* Exclude nfs_delegation_claim_locks() */ |
| 6046 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6047 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6048 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6049 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6050 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6051 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6052 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6053 | } |
| 6054 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6055 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6056 | if (status != 0) |
| 6057 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6058 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6059 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6060 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6061 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6062 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6063 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6064 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6065 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6066 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6067 | 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] | 6068 | status = PTR_ERR(task); |
| 6069 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6070 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6071 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6072 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6073 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6074 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6075 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6076 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | } |
| 6078 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6079 | struct nfs4_lockdata { |
| 6080 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6081 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6082 | struct nfs4_lock_state *lsp; |
| 6083 | struct nfs_open_context *ctx; |
| 6084 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6085 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6086 | int rpc_status; |
| 6087 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6088 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6089 | }; |
| 6090 | |
| 6091 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6092 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6093 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6094 | { |
| 6095 | struct nfs4_lockdata *p; |
| 6096 | struct inode *inode = lsp->ls_state->inode; |
| 6097 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6098 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6099 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6100 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6101 | if (p == NULL) |
| 6102 | return NULL; |
| 6103 | |
| 6104 | p->arg.fh = NFS_FH(inode); |
| 6105 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6106 | 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] | 6107 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6108 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6109 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6110 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6111 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6112 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6113 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6114 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6115 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6116 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6117 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6118 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6119 | atomic_inc(&lsp->ls_count); |
| 6120 | p->ctx = get_nfs_open_context(ctx); |
| 6121 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6122 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6123 | out_free_seqid: |
| 6124 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6125 | out_free: |
| 6126 | kfree(p); |
| 6127 | return NULL; |
| 6128 | } |
| 6129 | |
| 6130 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6131 | { |
| 6132 | struct nfs4_lockdata *data = calldata; |
| 6133 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6135 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6136 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6137 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6138 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6139 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6140 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6141 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6142 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6143 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6144 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6145 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6146 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6147 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6148 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6149 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6150 | &data->lsp->ls_stateid); |
| 6151 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6152 | if (!nfs4_valid_open_stateid(state)) { |
| 6153 | data->rpc_status = -EBADF; |
| 6154 | task->tk_action = NULL; |
| 6155 | goto out_release_open_seqid; |
| 6156 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6157 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6158 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6159 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6160 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6161 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6162 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6163 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6164 | nfs_release_seqid(data->arg.open_seqid); |
| 6165 | out_release_lock_seqid: |
| 6166 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6167 | out_wait: |
| 6168 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6169 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6170 | } |
| 6171 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6172 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6173 | { |
| 6174 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6175 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6176 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6177 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6178 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6179 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6180 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6181 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6182 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6183 | switch (task->tk_status) { |
| 6184 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6185 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6186 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6187 | if (data->arg.new_lock) { |
| 6188 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6189 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6190 | rpc_restart_call_prepare(task); |
| 6191 | break; |
| 6192 | } |
| 6193 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6194 | if (data->arg.new_lock_owner != 0) { |
| 6195 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6196 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6197 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6198 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6199 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6200 | break; |
| 6201 | case -NFS4ERR_BAD_STATEID: |
| 6202 | case -NFS4ERR_OLD_STATEID: |
| 6203 | case -NFS4ERR_STALE_STATEID: |
| 6204 | case -NFS4ERR_EXPIRED: |
| 6205 | if (data->arg.new_lock_owner != 0) { |
| 6206 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6207 | &lsp->ls_state->open_stateid)) |
| 6208 | rpc_restart_call_prepare(task); |
| 6209 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6210 | &lsp->ls_stateid)) |
| 6211 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6212 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6213 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | static void nfs4_lock_release(void *calldata) |
| 6217 | { |
| 6218 | struct nfs4_lockdata *data = calldata; |
| 6219 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6220 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6221 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6222 | if (data->cancelled != 0) { |
| 6223 | struct rpc_task *task; |
| 6224 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6225 | data->arg.lock_seqid); |
| 6226 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6227 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6228 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6229 | } else |
| 6230 | nfs_free_seqid(data->arg.lock_seqid); |
| 6231 | nfs4_put_lock_state(data->lsp); |
| 6232 | put_nfs_open_context(data->ctx); |
| 6233 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6234 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6238 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6239 | .rpc_call_done = nfs4_lock_done, |
| 6240 | .rpc_release = nfs4_lock_release, |
| 6241 | }; |
| 6242 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6243 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6244 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6245 | switch (error) { |
| 6246 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6247 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6248 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6249 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6250 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6251 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6252 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6253 | break; |
| 6254 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6255 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6256 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6257 | }; |
| 6258 | } |
| 6259 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6260 | 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] | 6261 | { |
| 6262 | struct nfs4_lockdata *data; |
| 6263 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6264 | struct rpc_message msg = { |
| 6265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6266 | .rpc_cred = state->owner->so_cred, |
| 6267 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6268 | struct rpc_task_setup task_setup_data = { |
| 6269 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6270 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6271 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6272 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6273 | .flags = RPC_TASK_ASYNC, |
| 6274 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6275 | int ret; |
| 6276 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6277 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6278 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6279 | fl->fl_u.nfs4_fl.owner, |
| 6280 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6281 | if (data == NULL) |
| 6282 | return -ENOMEM; |
| 6283 | if (IS_SETLKW(cmd)) |
| 6284 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6285 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6286 | msg.rpc_argp = &data->arg; |
| 6287 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6288 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6289 | if (recovery_type > NFS_LOCK_NEW) { |
| 6290 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6291 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6292 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6293 | } else |
| 6294 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6295 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6296 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6297 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6298 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6299 | if (ret == 0) { |
| 6300 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6301 | if (ret) |
| 6302 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6303 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6304 | } else |
| 6305 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6306 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6307 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6308 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6309 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6313 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6314 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6315 | struct nfs4_exception exception = { |
| 6316 | .inode = state->inode, |
| 6317 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6318 | int err; |
| 6319 | |
| 6320 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6321 | /* Cache the lock if possible... */ |
| 6322 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6323 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6324 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6325 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6326 | break; |
| 6327 | nfs4_handle_exception(server, err, &exception); |
| 6328 | } while (exception.retry); |
| 6329 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6333 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6334 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6335 | struct nfs4_exception exception = { |
| 6336 | .inode = state->inode, |
| 6337 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6338 | int err; |
| 6339 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6340 | err = nfs4_set_lock_state(state, request); |
| 6341 | if (err != 0) |
| 6342 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6343 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6344 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6345 | return 0; |
| 6346 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6347 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6348 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6349 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6350 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6351 | switch (err) { |
| 6352 | default: |
| 6353 | goto out; |
| 6354 | case -NFS4ERR_GRACE: |
| 6355 | case -NFS4ERR_DELAY: |
| 6356 | nfs4_handle_exception(server, err, &exception); |
| 6357 | err = 0; |
| 6358 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6359 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6360 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6361 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | } |
| 6363 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6364 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6365 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6366 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6367 | struct nfs4_lock_state *lsp; |
| 6368 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6369 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6370 | status = nfs4_set_lock_state(state, request); |
| 6371 | if (status != 0) |
| 6372 | return status; |
| 6373 | lsp = request->fl_u.nfs4_fl.owner; |
| 6374 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6375 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6376 | return 0; |
| 6377 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6378 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6379 | } |
| 6380 | #endif |
| 6381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6382 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6383 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6384 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6385 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6386 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6387 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6389 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6390 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6391 | if (status < 0) |
| 6392 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6393 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6394 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6395 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6396 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6397 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6398 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6399 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6400 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6401 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6402 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6403 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6404 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6405 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6406 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6407 | out: |
| 6408 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6409 | return status; |
| 6410 | } |
| 6411 | |
| 6412 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6413 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6414 | struct nfs4_exception exception = { |
| 6415 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6416 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6417 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | int err; |
| 6419 | |
| 6420 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6421 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6422 | if (err == -NFS4ERR_DENIED) |
| 6423 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6424 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6425 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6426 | } while (exception.retry); |
| 6427 | return err; |
| 6428 | } |
| 6429 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6430 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6431 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6432 | |
| 6433 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6434 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6435 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6436 | { |
| 6437 | int status = -ERESTARTSYS; |
| 6438 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6439 | |
| 6440 | while(!signalled()) { |
| 6441 | status = nfs4_proc_setlk(state, cmd, request); |
| 6442 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6443 | break; |
| 6444 | freezable_schedule_timeout_interruptible(timeout); |
| 6445 | timeout *= 2; |
| 6446 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6447 | status = -ERESTARTSYS; |
| 6448 | } |
| 6449 | return status; |
| 6450 | } |
| 6451 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6452 | #ifdef CONFIG_NFS_V4_1 |
| 6453 | struct nfs4_lock_waiter { |
| 6454 | struct task_struct *task; |
| 6455 | struct inode *inode; |
| 6456 | struct nfs_lowner *owner; |
| 6457 | bool notified; |
| 6458 | }; |
| 6459 | |
| 6460 | static int |
| 6461 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6462 | { |
| 6463 | int ret; |
| 6464 | struct cb_notify_lock_args *cbnl = key; |
| 6465 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6466 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6467 | *wowner = waiter->owner; |
| 6468 | |
| 6469 | /* Only wake if the callback was for the same owner */ |
| 6470 | if (lowner->clientid != wowner->clientid || |
| 6471 | lowner->id != wowner->id || |
| 6472 | lowner->s_dev != wowner->s_dev) |
| 6473 | return 0; |
| 6474 | |
| 6475 | /* Make sure it's for the right inode */ |
| 6476 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6477 | return 0; |
| 6478 | |
| 6479 | waiter->notified = true; |
| 6480 | |
| 6481 | /* override "private" so we can use default_wake_function */ |
| 6482 | wait->private = waiter->task; |
| 6483 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6484 | wait->private = waiter; |
| 6485 | return ret; |
| 6486 | } |
| 6487 | |
| 6488 | static int |
| 6489 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6490 | { |
| 6491 | int status = -ERESTARTSYS; |
| 6492 | unsigned long flags; |
| 6493 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6494 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6495 | struct nfs_client *clp = server->nfs_client; |
| 6496 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6497 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6498 | .id = lsp->ls_seqid.owner_id, |
| 6499 | .s_dev = server->s_dev }; |
| 6500 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6501 | .inode = state->inode, |
| 6502 | .owner = &owner, |
| 6503 | .notified = false }; |
| 6504 | wait_queue_t wait; |
| 6505 | |
| 6506 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6507 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6508 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6509 | |
| 6510 | init_wait(&wait); |
| 6511 | wait.private = &waiter; |
| 6512 | wait.func = nfs4_wake_lock_waiter; |
| 6513 | add_wait_queue(q, &wait); |
| 6514 | |
| 6515 | while(!signalled()) { |
| 6516 | status = nfs4_proc_setlk(state, cmd, request); |
| 6517 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6518 | break; |
| 6519 | |
| 6520 | status = -ERESTARTSYS; |
| 6521 | spin_lock_irqsave(&q->lock, flags); |
| 6522 | if (waiter.notified) { |
| 6523 | spin_unlock_irqrestore(&q->lock, flags); |
| 6524 | continue; |
| 6525 | } |
| 6526 | set_current_state(TASK_INTERRUPTIBLE); |
| 6527 | spin_unlock_irqrestore(&q->lock, flags); |
| 6528 | |
| 6529 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6530 | } |
| 6531 | |
| 6532 | finish_wait(q, &wait); |
| 6533 | return status; |
| 6534 | } |
| 6535 | #else /* !CONFIG_NFS_V4_1 */ |
| 6536 | static inline int |
| 6537 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6538 | { |
| 6539 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6540 | } |
| 6541 | #endif |
| 6542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6543 | static int |
| 6544 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6545 | { |
| 6546 | struct nfs_open_context *ctx; |
| 6547 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6548 | int status; |
| 6549 | |
| 6550 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6551 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6552 | state = ctx->state; |
| 6553 | |
| 6554 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6555 | return -EINVAL; |
| 6556 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6557 | if (IS_GETLK(cmd)) { |
| 6558 | if (state != NULL) |
| 6559 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6560 | return 0; |
| 6561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6562 | |
| 6563 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6564 | return -EINVAL; |
| 6565 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6566 | if (request->fl_type == F_UNLCK) { |
| 6567 | if (state != NULL) |
| 6568 | return nfs4_proc_unlck(state, cmd, request); |
| 6569 | return 0; |
| 6570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6571 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6572 | if (state == NULL) |
| 6573 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6574 | |
| 6575 | if ((request->fl_flags & FL_POSIX) && |
| 6576 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6577 | return -ENOLCK; |
| 6578 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6579 | /* |
| 6580 | * Don't rely on the VFS having checked the file open mode, |
| 6581 | * since it won't do this for flock() locks. |
| 6582 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6583 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6584 | case F_RDLCK: |
| 6585 | if (!(filp->f_mode & FMODE_READ)) |
| 6586 | return -EBADF; |
| 6587 | break; |
| 6588 | case F_WRLCK: |
| 6589 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6590 | return -EBADF; |
| 6591 | } |
| 6592 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6593 | status = nfs4_set_lock_state(state, request); |
| 6594 | if (status != 0) |
| 6595 | return status; |
| 6596 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6597 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6598 | } |
| 6599 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6600 | 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] | 6601 | { |
| 6602 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6603 | int err; |
| 6604 | |
| 6605 | err = nfs4_set_lock_state(state, fl); |
| 6606 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6607 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6608 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6609 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6610 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6611 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6612 | struct nfs_release_lockowner_data { |
| 6613 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6614 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6615 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6616 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6617 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6618 | }; |
| 6619 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6620 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6621 | { |
| 6622 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6623 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6624 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6625 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6626 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6627 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6631 | { |
| 6632 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6633 | struct nfs_server *server = data->server; |
| 6634 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6635 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6636 | |
| 6637 | switch (task->tk_status) { |
| 6638 | case 0: |
| 6639 | renew_lease(server, data->timestamp); |
| 6640 | break; |
| 6641 | case -NFS4ERR_STALE_CLIENTID: |
| 6642 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6643 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6644 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6645 | case -NFS4ERR_LEASE_MOVED: |
| 6646 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6647 | if (nfs4_async_handle_error(task, server, |
| 6648 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6649 | rpc_restart_call_prepare(task); |
| 6650 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6651 | } |
| 6652 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6653 | static void nfs4_release_lockowner_release(void *calldata) |
| 6654 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6655 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6656 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6657 | kfree(calldata); |
| 6658 | } |
| 6659 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6660 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6661 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6662 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6663 | .rpc_release = nfs4_release_lockowner_release, |
| 6664 | }; |
| 6665 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6666 | static void |
| 6667 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6668 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6669 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6670 | struct rpc_message msg = { |
| 6671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6672 | }; |
| 6673 | |
| 6674 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6675 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6676 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6677 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6678 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6679 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6680 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6681 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6682 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6683 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6684 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6685 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6686 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6687 | msg.rpc_resp = &data->res; |
| 6688 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6689 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6690 | } |
| 6691 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6692 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6693 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6694 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6695 | struct dentry *unused, struct inode *inode, |
| 6696 | const char *key, const void *buf, |
| 6697 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6698 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6699 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6702 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6703 | struct dentry *unused, struct inode *inode, |
| 6704 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6705 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6706 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6709 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6710 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6711 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6712 | } |
| 6713 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6714 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6715 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6716 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6717 | struct dentry *unused, struct inode *inode, |
| 6718 | const char *key, const void *buf, |
| 6719 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6720 | { |
| 6721 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6722 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6723 | |
| 6724 | return -EOPNOTSUPP; |
| 6725 | } |
| 6726 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6727 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6728 | struct dentry *unused, struct inode *inode, |
| 6729 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6730 | { |
| 6731 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6732 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6733 | return -EOPNOTSUPP; |
| 6734 | } |
| 6735 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6736 | static ssize_t |
| 6737 | 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] | 6738 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6739 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6740 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6741 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6742 | len = security_inode_listsecurity(inode, list, list_len); |
| 6743 | if (list_len && len > list_len) |
| 6744 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6745 | } |
| 6746 | return len; |
| 6747 | } |
| 6748 | |
| 6749 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6750 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6751 | .get = nfs4_xattr_get_nfs4_label, |
| 6752 | .set = nfs4_xattr_set_nfs4_label, |
| 6753 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6754 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6755 | #else |
| 6756 | |
| 6757 | static ssize_t |
| 6758 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6759 | { |
| 6760 | return 0; |
| 6761 | } |
| 6762 | |
| 6763 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6764 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6765 | /* |
| 6766 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6767 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6768 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6769 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6770 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6771 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6772 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6773 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6774 | return; |
| 6775 | |
| 6776 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6777 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6778 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6779 | fattr->nlink = 2; |
| 6780 | } |
| 6781 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6782 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6783 | const struct qstr *name, |
| 6784 | struct nfs4_fs_locations *fs_locations, |
| 6785 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6786 | { |
| 6787 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6788 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6789 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6790 | }; |
| 6791 | struct nfs4_fs_locations_arg args = { |
| 6792 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6793 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6794 | .page = page, |
| 6795 | .bitmask = bitmask, |
| 6796 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6797 | struct nfs4_fs_locations_res res = { |
| 6798 | .fs_locations = fs_locations, |
| 6799 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6800 | struct rpc_message msg = { |
| 6801 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6802 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6803 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6804 | }; |
| 6805 | int status; |
| 6806 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6807 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6808 | |
| 6809 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6810 | * is not supported */ |
| 6811 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6812 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6813 | else |
| 6814 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6815 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6816 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6817 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6818 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6819 | 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] | 6820 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6821 | return status; |
| 6822 | } |
| 6823 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6824 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6825 | const struct qstr *name, |
| 6826 | struct nfs4_fs_locations *fs_locations, |
| 6827 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6828 | { |
| 6829 | struct nfs4_exception exception = { }; |
| 6830 | int err; |
| 6831 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6832 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6833 | fs_locations, page); |
| 6834 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6835 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6836 | &exception); |
| 6837 | } while (exception.retry); |
| 6838 | return err; |
| 6839 | } |
| 6840 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6841 | /* |
| 6842 | * This operation also signals the server that this client is |
| 6843 | * performing migration recovery. The server can stop returning |
| 6844 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6845 | * appended to this compound to identify the client ID which is |
| 6846 | * performing recovery. |
| 6847 | */ |
| 6848 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6849 | struct nfs4_fs_locations *locations, |
| 6850 | struct page *page, struct rpc_cred *cred) |
| 6851 | { |
| 6852 | struct nfs_server *server = NFS_SERVER(inode); |
| 6853 | struct rpc_clnt *clnt = server->client; |
| 6854 | u32 bitmask[2] = { |
| 6855 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6856 | }; |
| 6857 | struct nfs4_fs_locations_arg args = { |
| 6858 | .clientid = server->nfs_client->cl_clientid, |
| 6859 | .fh = NFS_FH(inode), |
| 6860 | .page = page, |
| 6861 | .bitmask = bitmask, |
| 6862 | .migration = 1, /* skip LOOKUP */ |
| 6863 | .renew = 1, /* append RENEW */ |
| 6864 | }; |
| 6865 | struct nfs4_fs_locations_res res = { |
| 6866 | .fs_locations = locations, |
| 6867 | .migration = 1, |
| 6868 | .renew = 1, |
| 6869 | }; |
| 6870 | struct rpc_message msg = { |
| 6871 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6872 | .rpc_argp = &args, |
| 6873 | .rpc_resp = &res, |
| 6874 | .rpc_cred = cred, |
| 6875 | }; |
| 6876 | unsigned long now = jiffies; |
| 6877 | int status; |
| 6878 | |
| 6879 | nfs_fattr_init(&locations->fattr); |
| 6880 | locations->server = server; |
| 6881 | locations->nlocations = 0; |
| 6882 | |
| 6883 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6884 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6885 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6886 | &args.seq_args, &res.seq_res); |
| 6887 | if (status) |
| 6888 | return status; |
| 6889 | |
| 6890 | renew_lease(server, now); |
| 6891 | return 0; |
| 6892 | } |
| 6893 | |
| 6894 | #ifdef CONFIG_NFS_V4_1 |
| 6895 | |
| 6896 | /* |
| 6897 | * This operation also signals the server that this client is |
| 6898 | * performing migration recovery. The server can stop asserting |
| 6899 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6900 | * performing this operation is identified in the SEQUENCE |
| 6901 | * operation in this compound. |
| 6902 | * |
| 6903 | * When the client supports GETATTR(fs_locations_info), it can |
| 6904 | * be plumbed in here. |
| 6905 | */ |
| 6906 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6907 | struct nfs4_fs_locations *locations, |
| 6908 | struct page *page, struct rpc_cred *cred) |
| 6909 | { |
| 6910 | struct nfs_server *server = NFS_SERVER(inode); |
| 6911 | struct rpc_clnt *clnt = server->client; |
| 6912 | u32 bitmask[2] = { |
| 6913 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6914 | }; |
| 6915 | struct nfs4_fs_locations_arg args = { |
| 6916 | .fh = NFS_FH(inode), |
| 6917 | .page = page, |
| 6918 | .bitmask = bitmask, |
| 6919 | .migration = 1, /* skip LOOKUP */ |
| 6920 | }; |
| 6921 | struct nfs4_fs_locations_res res = { |
| 6922 | .fs_locations = locations, |
| 6923 | .migration = 1, |
| 6924 | }; |
| 6925 | struct rpc_message msg = { |
| 6926 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6927 | .rpc_argp = &args, |
| 6928 | .rpc_resp = &res, |
| 6929 | .rpc_cred = cred, |
| 6930 | }; |
| 6931 | int status; |
| 6932 | |
| 6933 | nfs_fattr_init(&locations->fattr); |
| 6934 | locations->server = server; |
| 6935 | locations->nlocations = 0; |
| 6936 | |
| 6937 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6938 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6939 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6940 | &args.seq_args, &res.seq_res); |
| 6941 | if (status == NFS4_OK && |
| 6942 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6943 | status = -NFS4ERR_LEASE_MOVED; |
| 6944 | return status; |
| 6945 | } |
| 6946 | |
| 6947 | #endif /* CONFIG_NFS_V4_1 */ |
| 6948 | |
| 6949 | /** |
| 6950 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6951 | * @inode: inode on FSID that is migrating |
| 6952 | * @locations: result of query |
| 6953 | * @page: buffer |
| 6954 | * @cred: credential to use for this operation |
| 6955 | * |
| 6956 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6957 | * operation failed, or a negative errno if a local error occurred. |
| 6958 | * |
| 6959 | * On success, "locations" is filled in, but if the server has |
| 6960 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6961 | * asserted. |
| 6962 | * |
| 6963 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6964 | * from this client that require migration recovery. |
| 6965 | */ |
| 6966 | int nfs4_proc_get_locations(struct inode *inode, |
| 6967 | struct nfs4_fs_locations *locations, |
| 6968 | struct page *page, struct rpc_cred *cred) |
| 6969 | { |
| 6970 | struct nfs_server *server = NFS_SERVER(inode); |
| 6971 | struct nfs_client *clp = server->nfs_client; |
| 6972 | const struct nfs4_mig_recovery_ops *ops = |
| 6973 | clp->cl_mvops->mig_recovery_ops; |
| 6974 | struct nfs4_exception exception = { }; |
| 6975 | int status; |
| 6976 | |
| 6977 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6978 | (unsigned long long)server->fsid.major, |
| 6979 | (unsigned long long)server->fsid.minor, |
| 6980 | clp->cl_hostname); |
| 6981 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6982 | |
| 6983 | do { |
| 6984 | status = ops->get_locations(inode, locations, page, cred); |
| 6985 | if (status != -NFS4ERR_DELAY) |
| 6986 | break; |
| 6987 | nfs4_handle_exception(server, status, &exception); |
| 6988 | } while (exception.retry); |
| 6989 | return status; |
| 6990 | } |
| 6991 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6992 | /* |
| 6993 | * This operation also signals the server that this client is |
| 6994 | * performing "lease moved" recovery. The server can stop |
| 6995 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6996 | * is appended to this compound to identify the client ID which is |
| 6997 | * performing recovery. |
| 6998 | */ |
| 6999 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7000 | { |
| 7001 | struct nfs_server *server = NFS_SERVER(inode); |
| 7002 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7003 | struct rpc_clnt *clnt = server->client; |
| 7004 | struct nfs4_fsid_present_arg args = { |
| 7005 | .fh = NFS_FH(inode), |
| 7006 | .clientid = clp->cl_clientid, |
| 7007 | .renew = 1, /* append RENEW */ |
| 7008 | }; |
| 7009 | struct nfs4_fsid_present_res res = { |
| 7010 | .renew = 1, |
| 7011 | }; |
| 7012 | struct rpc_message msg = { |
| 7013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7014 | .rpc_argp = &args, |
| 7015 | .rpc_resp = &res, |
| 7016 | .rpc_cred = cred, |
| 7017 | }; |
| 7018 | unsigned long now = jiffies; |
| 7019 | int status; |
| 7020 | |
| 7021 | res.fh = nfs_alloc_fhandle(); |
| 7022 | if (res.fh == NULL) |
| 7023 | return -ENOMEM; |
| 7024 | |
| 7025 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7026 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7027 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7028 | &args.seq_args, &res.seq_res); |
| 7029 | nfs_free_fhandle(res.fh); |
| 7030 | if (status) |
| 7031 | return status; |
| 7032 | |
| 7033 | do_renew_lease(clp, now); |
| 7034 | return 0; |
| 7035 | } |
| 7036 | |
| 7037 | #ifdef CONFIG_NFS_V4_1 |
| 7038 | |
| 7039 | /* |
| 7040 | * This operation also signals the server that this client is |
| 7041 | * performing "lease moved" recovery. The server can stop asserting |
| 7042 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7043 | * this operation is identified in the SEQUENCE operation in this |
| 7044 | * compound. |
| 7045 | */ |
| 7046 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7047 | { |
| 7048 | struct nfs_server *server = NFS_SERVER(inode); |
| 7049 | struct rpc_clnt *clnt = server->client; |
| 7050 | struct nfs4_fsid_present_arg args = { |
| 7051 | .fh = NFS_FH(inode), |
| 7052 | }; |
| 7053 | struct nfs4_fsid_present_res res = { |
| 7054 | }; |
| 7055 | struct rpc_message msg = { |
| 7056 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7057 | .rpc_argp = &args, |
| 7058 | .rpc_resp = &res, |
| 7059 | .rpc_cred = cred, |
| 7060 | }; |
| 7061 | int status; |
| 7062 | |
| 7063 | res.fh = nfs_alloc_fhandle(); |
| 7064 | if (res.fh == NULL) |
| 7065 | return -ENOMEM; |
| 7066 | |
| 7067 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7068 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7069 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7070 | &args.seq_args, &res.seq_res); |
| 7071 | nfs_free_fhandle(res.fh); |
| 7072 | if (status == NFS4_OK && |
| 7073 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7074 | status = -NFS4ERR_LEASE_MOVED; |
| 7075 | return status; |
| 7076 | } |
| 7077 | |
| 7078 | #endif /* CONFIG_NFS_V4_1 */ |
| 7079 | |
| 7080 | /** |
| 7081 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7082 | * @inode: inode on FSID to check |
| 7083 | * @cred: credential to use for this operation |
| 7084 | * |
| 7085 | * Server indicates whether the FSID is present, moved, or not |
| 7086 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7087 | * condition for this client ID. |
| 7088 | * |
| 7089 | * Returns NFS4_OK if the FSID is present on this server, |
| 7090 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7091 | * NFS4ERR code if some error occurred on the server, or a |
| 7092 | * negative errno if a local failure occurred. |
| 7093 | */ |
| 7094 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7095 | { |
| 7096 | struct nfs_server *server = NFS_SERVER(inode); |
| 7097 | struct nfs_client *clp = server->nfs_client; |
| 7098 | const struct nfs4_mig_recovery_ops *ops = |
| 7099 | clp->cl_mvops->mig_recovery_ops; |
| 7100 | struct nfs4_exception exception = { }; |
| 7101 | int status; |
| 7102 | |
| 7103 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7104 | (unsigned long long)server->fsid.major, |
| 7105 | (unsigned long long)server->fsid.minor, |
| 7106 | clp->cl_hostname); |
| 7107 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7108 | |
| 7109 | do { |
| 7110 | status = ops->fsid_present(inode, cred); |
| 7111 | if (status != -NFS4ERR_DELAY) |
| 7112 | break; |
| 7113 | nfs4_handle_exception(server, status, &exception); |
| 7114 | } while (exception.retry); |
| 7115 | return status; |
| 7116 | } |
| 7117 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7118 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7119 | * If 'use_integrity' is true and the state managment nfs_client |
| 7120 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7121 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7122 | * Considerations sections. Otherwise, just use the user cred with the |
| 7123 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7124 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7125 | 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] | 7126 | { |
| 7127 | int status; |
| 7128 | struct nfs4_secinfo_arg args = { |
| 7129 | .dir_fh = NFS_FH(dir), |
| 7130 | .name = name, |
| 7131 | }; |
| 7132 | struct nfs4_secinfo_res res = { |
| 7133 | .flavors = flavors, |
| 7134 | }; |
| 7135 | struct rpc_message msg = { |
| 7136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7137 | .rpc_argp = &args, |
| 7138 | .rpc_resp = &res, |
| 7139 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7140 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7141 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7142 | |
| 7143 | if (use_integrity) { |
| 7144 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7145 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7146 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7147 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7148 | |
| 7149 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7150 | |
| 7151 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7152 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7153 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7154 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7155 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7156 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7157 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7158 | if (cred) |
| 7159 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7160 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7161 | return status; |
| 7162 | } |
| 7163 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7164 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7165 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7166 | { |
| 7167 | struct nfs4_exception exception = { }; |
| 7168 | int err; |
| 7169 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7170 | err = -NFS4ERR_WRONGSEC; |
| 7171 | |
| 7172 | /* try to use integrity protection with machine cred */ |
| 7173 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7174 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7175 | |
| 7176 | /* |
| 7177 | * if unable to use integrity protection, or SECINFO with |
| 7178 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7179 | * disallowed by spec, but exists in deployed servers) use |
| 7180 | * the current filesystem's rpc_client and the user cred. |
| 7181 | */ |
| 7182 | if (err == -NFS4ERR_WRONGSEC) |
| 7183 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7184 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7185 | trace_nfs4_secinfo(dir, name, err); |
| 7186 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7187 | &exception); |
| 7188 | } while (exception.retry); |
| 7189 | return err; |
| 7190 | } |
| 7191 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7192 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7193 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7194 | * Check the exchange flags returned by the server for invalid flags, having |
| 7195 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7196 | * DS flags set. |
| 7197 | */ |
| 7198 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7199 | { |
| 7200 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7201 | goto out_inval; |
| 7202 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7203 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7204 | goto out_inval; |
| 7205 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7206 | goto out_inval; |
| 7207 | return NFS_OK; |
| 7208 | out_inval: |
| 7209 | return -NFS4ERR_INVAL; |
| 7210 | } |
| 7211 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7212 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7213 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7214 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7215 | { |
| 7216 | if (a->server_scope_sz == b->server_scope_sz && |
| 7217 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7218 | return true; |
| 7219 | |
| 7220 | return false; |
| 7221 | } |
| 7222 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7223 | static void |
| 7224 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7225 | { |
| 7226 | } |
| 7227 | |
| 7228 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7229 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7230 | }; |
| 7231 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7232 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7233 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7234 | * |
| 7235 | * The 4.1 client currently uses the same TCP connection for the |
| 7236 | * fore and backchannel. |
| 7237 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7238 | static |
| 7239 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7240 | struct rpc_xprt *xprt, |
| 7241 | struct nfs_client *clp, |
| 7242 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7243 | { |
| 7244 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7245 | struct nfs41_bind_conn_to_session_args args = { |
| 7246 | .client = clp, |
| 7247 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7248 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7249 | struct nfs41_bind_conn_to_session_res res; |
| 7250 | struct rpc_message msg = { |
| 7251 | .rpc_proc = |
| 7252 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7253 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7254 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7255 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7256 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7257 | struct rpc_task_setup task_setup_data = { |
| 7258 | .rpc_client = clnt, |
| 7259 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7260 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7261 | .rpc_message = &msg, |
| 7262 | .flags = RPC_TASK_TIMEOUT, |
| 7263 | }; |
| 7264 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7265 | |
| 7266 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7268 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7269 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7270 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7271 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7272 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7273 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7274 | args.dir = NFS4_CDFC4_FORE; |
| 7275 | |
| 7276 | task = rpc_run_task(&task_setup_data); |
| 7277 | if (!IS_ERR(task)) { |
| 7278 | status = task->tk_status; |
| 7279 | rpc_put_task(task); |
| 7280 | } else |
| 7281 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7282 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7283 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7284 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7285 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7286 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7287 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7288 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7289 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7290 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7291 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7292 | __func__); |
| 7293 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7294 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7295 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7296 | 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] | 7297 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7298 | __func__); |
| 7299 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7300 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7301 | } |
| 7302 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7303 | out: |
| 7304 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7305 | return status; |
| 7306 | } |
| 7307 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7308 | struct rpc_bind_conn_calldata { |
| 7309 | struct nfs_client *clp; |
| 7310 | struct rpc_cred *cred; |
| 7311 | }; |
| 7312 | |
| 7313 | static int |
| 7314 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7315 | struct rpc_xprt *xprt, |
| 7316 | void *calldata) |
| 7317 | { |
| 7318 | struct rpc_bind_conn_calldata *p = calldata; |
| 7319 | |
| 7320 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7321 | } |
| 7322 | |
| 7323 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7324 | { |
| 7325 | struct rpc_bind_conn_calldata data = { |
| 7326 | .clp = clp, |
| 7327 | .cred = cred, |
| 7328 | }; |
| 7329 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7330 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7331 | } |
| 7332 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7333 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7334 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7335 | * 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] | 7336 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7337 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7338 | .how = SP4_MACH_CRED, |
| 7339 | .enforce.u.words = { |
| 7340 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7341 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7342 | 1 << (OP_CREATE_SESSION - 32) | |
| 7343 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7344 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7345 | }, |
| 7346 | .allow.u.words = { |
| 7347 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7348 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7349 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7350 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7351 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7352 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7353 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7354 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7355 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7356 | 1 << (OP_FREE_STATEID - 32) | |
| 7357 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7358 | } |
| 7359 | }; |
| 7360 | |
| 7361 | /* |
| 7362 | * Select the state protection mode for client `clp' given the server results |
| 7363 | * from exchange_id in `sp'. |
| 7364 | * |
| 7365 | * Returns 0 on success, negative errno otherwise. |
| 7366 | */ |
| 7367 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7368 | struct nfs41_state_protection *sp) |
| 7369 | { |
| 7370 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7371 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7372 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7373 | 1 << (OP_CREATE_SESSION - 32) | |
| 7374 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7375 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7376 | }; |
| 7377 | unsigned int i; |
| 7378 | |
| 7379 | if (sp->how == SP4_MACH_CRED) { |
| 7380 | /* Print state protect result */ |
| 7381 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7382 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7383 | if (test_bit(i, sp->enforce.u.longs)) |
| 7384 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7385 | if (test_bit(i, sp->allow.u.longs)) |
| 7386 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7387 | } |
| 7388 | |
| 7389 | /* make sure nothing is on enforce list that isn't supported */ |
| 7390 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7391 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7392 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7393 | return -EINVAL; |
| 7394 | } |
| 7395 | } |
| 7396 | |
| 7397 | /* |
| 7398 | * Minimal mode - state operations are allowed to use machine |
| 7399 | * credential. Note this already happens by default, so the |
| 7400 | * client doesn't have to do anything more than the negotiation. |
| 7401 | * |
| 7402 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7403 | * we're already using the machine cred for exchange_id |
| 7404 | * and will never use a different cred. |
| 7405 | */ |
| 7406 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7407 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7408 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7409 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7410 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7411 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7412 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7413 | } else { |
| 7414 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7415 | return -EINVAL; |
| 7416 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7417 | |
| 7418 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7419 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7420 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7421 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7422 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7423 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7424 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7425 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7426 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7427 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7428 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7429 | &clp->cl_sp4_flags); |
| 7430 | } |
| 7431 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7432 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7433 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7434 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7435 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7436 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7437 | |
| 7438 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7439 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7440 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7441 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7442 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7443 | |
| 7444 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7445 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7446 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7447 | } |
| 7448 | |
| 7449 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7450 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7451 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7452 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7453 | } |
| 7454 | |
| 7455 | return 0; |
| 7456 | } |
| 7457 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7458 | struct nfs41_exchange_id_data { |
| 7459 | struct nfs41_exchange_id_res res; |
| 7460 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7461 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7462 | int rpc_status; |
| 7463 | }; |
| 7464 | |
| 7465 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7466 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7467 | struct nfs41_exchange_id_data *cdata = |
| 7468 | (struct nfs41_exchange_id_data *)data; |
| 7469 | struct nfs_client *clp = cdata->args.client; |
| 7470 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7471 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7472 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7473 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7474 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7475 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7476 | |
| 7477 | if (cdata->xprt && status == 0) { |
| 7478 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7479 | cdata->xprt); |
| 7480 | goto out; |
| 7481 | } |
| 7482 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7483 | if (status == 0) |
| 7484 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7485 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7486 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7487 | clp->cl_clientid = cdata->res.clientid; |
| 7488 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7489 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7490 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7491 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7492 | &clp->cl_session->session_state); |
| 7493 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7494 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7495 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7496 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7497 | clp->cl_serverowner = cdata->res.server_owner; |
| 7498 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7499 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7500 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7501 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7502 | clp->cl_implid = cdata->res.impl_id; |
| 7503 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7504 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7505 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7506 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7507 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7508 | dprintk("%s: server_scope mismatch detected\n", |
| 7509 | __func__); |
| 7510 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7511 | kfree(clp->cl_serverscope); |
| 7512 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7513 | } |
| 7514 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7515 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7516 | clp->cl_serverscope = cdata->res.server_scope; |
| 7517 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7518 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7519 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7520 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7521 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7522 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7523 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7524 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7525 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | static void nfs4_exchange_id_release(void *data) |
| 7529 | { |
| 7530 | struct nfs41_exchange_id_data *cdata = |
| 7531 | (struct nfs41_exchange_id_data *)data; |
| 7532 | |
| 7533 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7534 | if (cdata->xprt) { |
| 7535 | xprt_put(cdata->xprt); |
| 7536 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7537 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7538 | kfree(cdata->res.impl_id); |
| 7539 | kfree(cdata->res.server_scope); |
| 7540 | kfree(cdata->res.server_owner); |
| 7541 | kfree(cdata); |
| 7542 | } |
| 7543 | |
| 7544 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7545 | .rpc_call_done = nfs4_exchange_id_done, |
| 7546 | .rpc_release = nfs4_exchange_id_release, |
| 7547 | }; |
| 7548 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7549 | /* |
| 7550 | * _nfs4_proc_exchange_id() |
| 7551 | * |
| 7552 | * Wrapper for EXCHANGE_ID operation. |
| 7553 | */ |
| 7554 | 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] | 7555 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7556 | { |
| 7557 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7558 | struct rpc_message msg = { |
| 7559 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7560 | .rpc_cred = cred, |
| 7561 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7562 | struct rpc_task_setup task_setup_data = { |
| 7563 | .rpc_client = clp->cl_rpcclient, |
| 7564 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7565 | .rpc_message = &msg, |
| 7566 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7567 | }; |
| 7568 | struct nfs41_exchange_id_data *calldata; |
| 7569 | struct rpc_task *task; |
| 7570 | int status = -EIO; |
| 7571 | |
| 7572 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7573 | goto out; |
| 7574 | |
| 7575 | status = -ENOMEM; |
| 7576 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7577 | if (!calldata) |
| 7578 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7579 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7580 | if (!xprt) |
| 7581 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7582 | |
| 7583 | status = nfs4_init_uniform_client_string(clp); |
| 7584 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7585 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7586 | |
| 7587 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7588 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7589 | clp->cl_owner_id); |
| 7590 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7591 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7592 | GFP_NOFS); |
| 7593 | status = -ENOMEM; |
| 7594 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7595 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7596 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7597 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7598 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7599 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7600 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7601 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7602 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7603 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7604 | goto out_server_scope; |
| 7605 | |
| 7606 | switch (sp4_how) { |
| 7607 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7608 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7609 | break; |
| 7610 | |
| 7611 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7612 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7613 | break; |
| 7614 | |
| 7615 | default: |
| 7616 | /* unsupported! */ |
| 7617 | WARN_ON_ONCE(1); |
| 7618 | status = -EINVAL; |
| 7619 | goto out_impl_id; |
| 7620 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7621 | if (xprt) { |
| 7622 | calldata->xprt = xprt; |
| 7623 | task_setup_data.rpc_xprt = xprt; |
| 7624 | task_setup_data.flags = |
| 7625 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7626 | calldata->args.verifier = &clp->cl_confirm; |
| 7627 | } else { |
| 7628 | calldata->args.verifier = &verifier; |
| 7629 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7630 | calldata->args.client = clp; |
| 7631 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7632 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7633 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7634 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7635 | #else |
| 7636 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7637 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7638 | #endif |
| 7639 | msg.rpc_argp = &calldata->args; |
| 7640 | msg.rpc_resp = &calldata->res; |
| 7641 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7642 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7643 | task = rpc_run_task(&task_setup_data); |
| 7644 | if (IS_ERR(task)) { |
| 7645 | status = PTR_ERR(task); |
| 7646 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7647 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7648 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7649 | if (!xprt) { |
| 7650 | status = rpc_wait_for_completion_task(task); |
| 7651 | if (!status) |
| 7652 | status = calldata->rpc_status; |
| 7653 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7654 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7655 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7656 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7657 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7658 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7659 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7660 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7661 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7662 | clp->cl_implid->date.seconds, |
| 7663 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7664 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7665 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7666 | |
| 7667 | out_impl_id: |
| 7668 | kfree(calldata->res.impl_id); |
| 7669 | out_server_scope: |
| 7670 | kfree(calldata->res.server_scope); |
| 7671 | out_server_owner: |
| 7672 | kfree(calldata->res.server_owner); |
| 7673 | out_calldata: |
| 7674 | kfree(calldata); |
| 7675 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7676 | } |
| 7677 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7678 | /* |
| 7679 | * nfs4_proc_exchange_id() |
| 7680 | * |
| 7681 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7682 | * |
| 7683 | * Since the clientid has expired, all compounds using sessions |
| 7684 | * associated with the stale clientid will be returning |
| 7685 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7686 | * be in some phase of session reset. |
| 7687 | * |
| 7688 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7689 | */ |
| 7690 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7691 | { |
| 7692 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7693 | int status; |
| 7694 | |
| 7695 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7696 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7697 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7698 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7699 | if (!status) |
| 7700 | return 0; |
| 7701 | } |
| 7702 | |
| 7703 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7704 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7705 | } |
| 7706 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7707 | /** |
| 7708 | * nfs4_test_session_trunk |
| 7709 | * |
| 7710 | * This is an add_xprt_test() test function called from |
| 7711 | * rpc_clnt_setup_test_and_add_xprt. |
| 7712 | * |
| 7713 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7714 | * and is dereferrenced in nfs4_exchange_id_release |
| 7715 | * |
| 7716 | * Upon success, add the new transport to the rpc_clnt |
| 7717 | * |
| 7718 | * @clnt: struct rpc_clnt to get new transport |
| 7719 | * @xprt: the rpc_xprt to test |
| 7720 | * @data: call data for _nfs4_proc_exchange_id. |
| 7721 | */ |
| 7722 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7723 | void *data) |
| 7724 | { |
| 7725 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7726 | u32 sp4_how; |
| 7727 | |
| 7728 | dprintk("--> %s try %s\n", __func__, |
| 7729 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7730 | |
| 7731 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7732 | |
| 7733 | /* Test connection for session trunking. Async exchange_id call */ |
| 7734 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7735 | } |
| 7736 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7737 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7738 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7739 | struct rpc_cred *cred) |
| 7740 | { |
| 7741 | struct rpc_message msg = { |
| 7742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7743 | .rpc_argp = clp, |
| 7744 | .rpc_cred = cred, |
| 7745 | }; |
| 7746 | int status; |
| 7747 | |
| 7748 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7749 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7750 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7751 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7752 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7753 | return status; |
| 7754 | } |
| 7755 | |
| 7756 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7757 | struct rpc_cred *cred) |
| 7758 | { |
| 7759 | unsigned int loop; |
| 7760 | int ret; |
| 7761 | |
| 7762 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7763 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7764 | switch (ret) { |
| 7765 | case -NFS4ERR_DELAY: |
| 7766 | case -NFS4ERR_CLIENTID_BUSY: |
| 7767 | ssleep(1); |
| 7768 | break; |
| 7769 | default: |
| 7770 | return ret; |
| 7771 | } |
| 7772 | } |
| 7773 | return 0; |
| 7774 | } |
| 7775 | |
| 7776 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7777 | { |
| 7778 | struct rpc_cred *cred; |
| 7779 | int ret = 0; |
| 7780 | |
| 7781 | if (clp->cl_mvops->minor_version < 1) |
| 7782 | goto out; |
| 7783 | if (clp->cl_exchange_flags == 0) |
| 7784 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7785 | if (clp->cl_preserve_clid) |
| 7786 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7787 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7788 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7789 | if (cred) |
| 7790 | put_rpccred(cred); |
| 7791 | switch (ret) { |
| 7792 | case 0: |
| 7793 | case -NFS4ERR_STALE_CLIENTID: |
| 7794 | clp->cl_exchange_flags = 0; |
| 7795 | } |
| 7796 | out: |
| 7797 | return ret; |
| 7798 | } |
| 7799 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7800 | struct nfs4_get_lease_time_data { |
| 7801 | struct nfs4_get_lease_time_args *args; |
| 7802 | struct nfs4_get_lease_time_res *res; |
| 7803 | struct nfs_client *clp; |
| 7804 | }; |
| 7805 | |
| 7806 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7807 | void *calldata) |
| 7808 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7809 | struct nfs4_get_lease_time_data *data = |
| 7810 | (struct nfs4_get_lease_time_data *)calldata; |
| 7811 | |
| 7812 | dprintk("--> %s\n", __func__); |
| 7813 | /* just setup sequence, do not trigger session recovery |
| 7814 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7815 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7816 | &data->args->la_seq_args, |
| 7817 | &data->res->lr_seq_res, |
| 7818 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7819 | dprintk("<-- %s\n", __func__); |
| 7820 | } |
| 7821 | |
| 7822 | /* |
| 7823 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7824 | * from sequence operation or clientid errors. |
| 7825 | */ |
| 7826 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7827 | { |
| 7828 | struct nfs4_get_lease_time_data *data = |
| 7829 | (struct nfs4_get_lease_time_data *)calldata; |
| 7830 | |
| 7831 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7832 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7833 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7834 | switch (task->tk_status) { |
| 7835 | case -NFS4ERR_DELAY: |
| 7836 | case -NFS4ERR_GRACE: |
| 7837 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7838 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7839 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7840 | /* fall through */ |
| 7841 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7842 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7843 | return; |
| 7844 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7845 | dprintk("<-- %s\n", __func__); |
| 7846 | } |
| 7847 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7848 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7849 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7850 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7851 | }; |
| 7852 | |
| 7853 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7854 | { |
| 7855 | struct rpc_task *task; |
| 7856 | struct nfs4_get_lease_time_args args; |
| 7857 | struct nfs4_get_lease_time_res res = { |
| 7858 | .lr_fsinfo = fsinfo, |
| 7859 | }; |
| 7860 | struct nfs4_get_lease_time_data data = { |
| 7861 | .args = &args, |
| 7862 | .res = &res, |
| 7863 | .clp = clp, |
| 7864 | }; |
| 7865 | struct rpc_message msg = { |
| 7866 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7867 | .rpc_argp = &args, |
| 7868 | .rpc_resp = &res, |
| 7869 | }; |
| 7870 | struct rpc_task_setup task_setup = { |
| 7871 | .rpc_client = clp->cl_rpcclient, |
| 7872 | .rpc_message = &msg, |
| 7873 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7874 | .callback_data = &data, |
| 7875 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7876 | }; |
| 7877 | int status; |
| 7878 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7879 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7880 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7881 | dprintk("--> %s\n", __func__); |
| 7882 | task = rpc_run_task(&task_setup); |
| 7883 | |
| 7884 | if (IS_ERR(task)) |
| 7885 | status = PTR_ERR(task); |
| 7886 | else { |
| 7887 | status = task->tk_status; |
| 7888 | rpc_put_task(task); |
| 7889 | } |
| 7890 | dprintk("<-- %s return %d\n", __func__, status); |
| 7891 | |
| 7892 | return status; |
| 7893 | } |
| 7894 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7895 | /* |
| 7896 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7897 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7898 | * use them. |
| 7899 | * |
| 7900 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7901 | * always set csa_cachethis to FALSE because the current implementation |
| 7902 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7903 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7904 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7905 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7906 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7907 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7908 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7909 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7910 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7911 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7912 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7913 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7914 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7915 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7916 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7917 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7918 | |
| 7919 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7920 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7921 | __func__, |
| 7922 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7923 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7924 | |
| 7925 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7926 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7927 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7928 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7929 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7930 | 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] | 7931 | |
| 7932 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7933 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7934 | __func__, |
| 7935 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7936 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7937 | args->bc_attrs.max_reqs); |
| 7938 | } |
| 7939 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7940 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7941 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7942 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7943 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7944 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7945 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7946 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7947 | return -EINVAL; |
| 7948 | /* |
| 7949 | * Our requested max_ops is the minimum we need; we're not |
| 7950 | * prepared to break up compounds into smaller pieces than that. |
| 7951 | * So, no point even trying to continue if the server won't |
| 7952 | * cooperate: |
| 7953 | */ |
| 7954 | if (rcvd->max_ops < sent->max_ops) |
| 7955 | return -EINVAL; |
| 7956 | if (rcvd->max_reqs == 0) |
| 7957 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7958 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7959 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7960 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7961 | } |
| 7962 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7963 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7964 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7965 | { |
| 7966 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7967 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7968 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7969 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7970 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7971 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7972 | return -EINVAL; |
| 7973 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7974 | return -EINVAL; |
| 7975 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7976 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7977 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7978 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7979 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7980 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7981 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7982 | return 0; |
| 7983 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7984 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7985 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7986 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7987 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7988 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7989 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7990 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7991 | if (ret) |
| 7992 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7993 | return nfs4_verify_back_channel_attrs(args, res); |
| 7994 | } |
| 7995 | |
| 7996 | static void nfs4_update_session(struct nfs4_session *session, |
| 7997 | struct nfs41_create_session_res *res) |
| 7998 | { |
| 7999 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8000 | /* Mark client id and session as being confirmed */ |
| 8001 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8002 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8003 | session->flags = res->flags; |
| 8004 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8005 | if (res->flags & SESSION4_BACK_CHAN) |
| 8006 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8007 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8008 | } |
| 8009 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8010 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8011 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8012 | { |
| 8013 | struct nfs4_session *session = clp->cl_session; |
| 8014 | struct nfs41_create_session_args args = { |
| 8015 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8016 | .clientid = clp->cl_clientid, |
| 8017 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8018 | .cb_program = NFS4_CALLBACK, |
| 8019 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8020 | struct nfs41_create_session_res res; |
| 8021 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8022 | struct rpc_message msg = { |
| 8023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8024 | .rpc_argp = &args, |
| 8025 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8026 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8027 | }; |
| 8028 | int status; |
| 8029 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8030 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8031 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8032 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8033 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8034 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8035 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8036 | switch (status) { |
| 8037 | case -NFS4ERR_STALE_CLIENTID: |
| 8038 | case -NFS4ERR_DELAY: |
| 8039 | case -ETIMEDOUT: |
| 8040 | case -EACCES: |
| 8041 | case -EAGAIN: |
| 8042 | goto out; |
| 8043 | }; |
| 8044 | |
| 8045 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8046 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8047 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8048 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8049 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8050 | if (status) |
| 8051 | goto out; |
| 8052 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8053 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8054 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8055 | return status; |
| 8056 | } |
| 8057 | |
| 8058 | /* |
| 8059 | * Issues a CREATE_SESSION operation to the server. |
| 8060 | * It is the responsibility of the caller to verify the session is |
| 8061 | * expired before calling this routine. |
| 8062 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8063 | 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] | 8064 | { |
| 8065 | int status; |
| 8066 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8067 | struct nfs4_session *session = clp->cl_session; |
| 8068 | |
| 8069 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8070 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8071 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8072 | if (status) |
| 8073 | goto out; |
| 8074 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8075 | /* Init or reset the session slot tables */ |
| 8076 | status = nfs4_setup_session_slot_tables(session); |
| 8077 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8078 | if (status) |
| 8079 | goto out; |
| 8080 | |
| 8081 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8082 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8083 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8084 | out: |
| 8085 | dprintk("<-- %s\n", __func__); |
| 8086 | return status; |
| 8087 | } |
| 8088 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8089 | /* |
| 8090 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8091 | * The caller must serialize access to this routine. |
| 8092 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8093 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8094 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8095 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8096 | struct rpc_message msg = { |
| 8097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8098 | .rpc_argp = session, |
| 8099 | .rpc_cred = cred, |
| 8100 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8101 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8102 | |
| 8103 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8104 | |
| 8105 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8106 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8107 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8108 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8109 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8110 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8111 | |
| 8112 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8113 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8114 | "Session has been destroyed regardless...\n", status); |
| 8115 | |
| 8116 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8117 | return status; |
| 8118 | } |
| 8119 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8120 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8121 | * Renew the cl_session lease. |
| 8122 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8123 | struct nfs4_sequence_data { |
| 8124 | struct nfs_client *clp; |
| 8125 | struct nfs4_sequence_args args; |
| 8126 | struct nfs4_sequence_res res; |
| 8127 | }; |
| 8128 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8129 | static void nfs41_sequence_release(void *data) |
| 8130 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8131 | struct nfs4_sequence_data *calldata = data; |
| 8132 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8133 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8134 | if (atomic_read(&clp->cl_count) > 1) |
| 8135 | nfs4_schedule_state_renewal(clp); |
| 8136 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8137 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8138 | } |
| 8139 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8140 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8141 | { |
| 8142 | switch(task->tk_status) { |
| 8143 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8144 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8145 | return -EAGAIN; |
| 8146 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8147 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8148 | } |
| 8149 | return 0; |
| 8150 | } |
| 8151 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8152 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8153 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8154 | struct nfs4_sequence_data *calldata = data; |
| 8155 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8156 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8157 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8158 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8159 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8160 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8161 | if (task->tk_status < 0) { |
| 8162 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8163 | if (atomic_read(&clp->cl_count) == 1) |
| 8164 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8165 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8166 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8167 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8168 | return; |
| 8169 | } |
| 8170 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8171 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8172 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8173 | dprintk("<-- %s\n", __func__); |
| 8174 | } |
| 8175 | |
| 8176 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8177 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8178 | struct nfs4_sequence_data *calldata = data; |
| 8179 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8180 | struct nfs4_sequence_args *args; |
| 8181 | struct nfs4_sequence_res *res; |
| 8182 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8183 | args = task->tk_msg.rpc_argp; |
| 8184 | res = task->tk_msg.rpc_resp; |
| 8185 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8186 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8187 | } |
| 8188 | |
| 8189 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8190 | .rpc_call_done = nfs41_sequence_call_done, |
| 8191 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8192 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8193 | }; |
| 8194 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8195 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8196 | struct rpc_cred *cred, |
| 8197 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8198 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8199 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8200 | struct rpc_message msg = { |
| 8201 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8202 | .rpc_cred = cred, |
| 8203 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8204 | struct rpc_task_setup task_setup_data = { |
| 8205 | .rpc_client = clp->cl_rpcclient, |
| 8206 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8207 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8208 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8209 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8210 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8211 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8212 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8213 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8214 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8215 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8216 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8217 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8218 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8219 | if (is_privileged) |
| 8220 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8221 | msg.rpc_argp = &calldata->args; |
| 8222 | msg.rpc_resp = &calldata->res; |
| 8223 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8224 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8225 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8226 | return rpc_run_task(&task_setup_data); |
| 8227 | } |
| 8228 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8229 | 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] | 8230 | { |
| 8231 | struct rpc_task *task; |
| 8232 | int ret = 0; |
| 8233 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8234 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8235 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8236 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8237 | if (IS_ERR(task)) |
| 8238 | ret = PTR_ERR(task); |
| 8239 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8240 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8241 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8242 | return ret; |
| 8243 | } |
| 8244 | |
| 8245 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8246 | { |
| 8247 | struct rpc_task *task; |
| 8248 | int ret; |
| 8249 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8250 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8251 | if (IS_ERR(task)) { |
| 8252 | ret = PTR_ERR(task); |
| 8253 | goto out; |
| 8254 | } |
| 8255 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8256 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8257 | ret = task->tk_status; |
| 8258 | rpc_put_task(task); |
| 8259 | out: |
| 8260 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8261 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8262 | } |
| 8263 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8264 | struct nfs4_reclaim_complete_data { |
| 8265 | struct nfs_client *clp; |
| 8266 | struct nfs41_reclaim_complete_args arg; |
| 8267 | struct nfs41_reclaim_complete_res res; |
| 8268 | }; |
| 8269 | |
| 8270 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8271 | { |
| 8272 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8273 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8274 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8275 | &calldata->arg.seq_args, |
| 8276 | &calldata->res.seq_res, |
| 8277 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8278 | } |
| 8279 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8280 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8281 | { |
| 8282 | switch(task->tk_status) { |
| 8283 | case 0: |
| 8284 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8285 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8286 | break; |
| 8287 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8288 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8289 | /* fall through */ |
| 8290 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8291 | return -EAGAIN; |
| 8292 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8293 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8294 | } |
| 8295 | return 0; |
| 8296 | } |
| 8297 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8298 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8299 | { |
| 8300 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8301 | struct nfs_client *clp = calldata->clp; |
| 8302 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8303 | |
| 8304 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8305 | if (!nfs41_sequence_done(task, res)) |
| 8306 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8307 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8308 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8309 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8310 | rpc_restart_call_prepare(task); |
| 8311 | return; |
| 8312 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8313 | dprintk("<-- %s\n", __func__); |
| 8314 | } |
| 8315 | |
| 8316 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8317 | { |
| 8318 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8319 | |
| 8320 | kfree(calldata); |
| 8321 | } |
| 8322 | |
| 8323 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8324 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8325 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8326 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8327 | }; |
| 8328 | |
| 8329 | /* |
| 8330 | * Issue a global reclaim complete. |
| 8331 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8332 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8333 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8334 | { |
| 8335 | struct nfs4_reclaim_complete_data *calldata; |
| 8336 | struct rpc_task *task; |
| 8337 | struct rpc_message msg = { |
| 8338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8339 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8340 | }; |
| 8341 | struct rpc_task_setup task_setup_data = { |
| 8342 | .rpc_client = clp->cl_rpcclient, |
| 8343 | .rpc_message = &msg, |
| 8344 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8345 | .flags = RPC_TASK_ASYNC, |
| 8346 | }; |
| 8347 | int status = -ENOMEM; |
| 8348 | |
| 8349 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8350 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8351 | if (calldata == NULL) |
| 8352 | goto out; |
| 8353 | calldata->clp = clp; |
| 8354 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8355 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8356 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8357 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8358 | msg.rpc_argp = &calldata->arg; |
| 8359 | msg.rpc_resp = &calldata->res; |
| 8360 | task_setup_data.callback_data = calldata; |
| 8361 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8362 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8363 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8364 | goto out; |
| 8365 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8366 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8367 | if (status == 0) |
| 8368 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8369 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8370 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8371 | out: |
| 8372 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8373 | return status; |
| 8374 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8375 | |
| 8376 | static void |
| 8377 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8378 | { |
| 8379 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8380 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8381 | |
| 8382 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8383 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8384 | &lgp->res.seq_res, task); |
| 8385 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8386 | } |
| 8387 | |
| 8388 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8389 | { |
| 8390 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8391 | |
| 8392 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8393 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8394 | dprintk("<-- %s\n", __func__); |
| 8395 | } |
| 8396 | |
| 8397 | static int |
| 8398 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8399 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8400 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8401 | struct inode *inode = lgp->args.inode; |
| 8402 | struct nfs_server *server = NFS_SERVER(inode); |
| 8403 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8404 | int nfs4err = task->tk_status; |
| 8405 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8406 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8407 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8408 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8409 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8410 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8411 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8412 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8413 | |
| 8414 | /* |
| 8415 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8416 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8417 | * retry go inband. |
| 8418 | */ |
| 8419 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8420 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8421 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8422 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8423 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8424 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8425 | */ |
| 8426 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8427 | status = -EOVERFLOW; |
| 8428 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8429 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8430 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8431 | * (or clients) writing to the same RAID stripe except when |
| 8432 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8433 | * |
| 8434 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8435 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8436 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8437 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8438 | if (lgp->args.minlength == 0) { |
| 8439 | status = -EOVERFLOW; |
| 8440 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8441 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8442 | status = -EBUSY; |
| 8443 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8444 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8445 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8446 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8447 | case -NFS4ERR_DELEG_REVOKED: |
| 8448 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8449 | case -NFS4ERR_EXPIRED: |
| 8450 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8451 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8452 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8453 | lo = NFS_I(inode)->layout; |
| 8454 | /* If the open stateid was bad, then recover it. */ |
| 8455 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8456 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8457 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8458 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8459 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8460 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8461 | break; |
| 8462 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8463 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8464 | /* |
| 8465 | * Mark the bad layout state as invalid, then retry |
| 8466 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8467 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8468 | spin_unlock(&inode->i_lock); |
| 8469 | pnfs_free_lseg_list(&head); |
| 8470 | status = -EAGAIN; |
| 8471 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8472 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8473 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8474 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8475 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8476 | if (!status) { |
| 8477 | if (exception->retry) |
| 8478 | status = -EAGAIN; |
| 8479 | else |
| 8480 | status = err; |
| 8481 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8482 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8483 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8484 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8485 | } |
| 8486 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8487 | static size_t max_response_pages(struct nfs_server *server) |
| 8488 | { |
| 8489 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8490 | return nfs_page_array_len(0, max_resp_sz); |
| 8491 | } |
| 8492 | |
| 8493 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8494 | { |
| 8495 | int i; |
| 8496 | |
| 8497 | if (!pages) |
| 8498 | return; |
| 8499 | |
| 8500 | for (i = 0; i < size; i++) { |
| 8501 | if (!pages[i]) |
| 8502 | break; |
| 8503 | __free_page(pages[i]); |
| 8504 | } |
| 8505 | kfree(pages); |
| 8506 | } |
| 8507 | |
| 8508 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8509 | { |
| 8510 | struct page **pages; |
| 8511 | int i; |
| 8512 | |
| 8513 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8514 | if (!pages) { |
| 8515 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8516 | return NULL; |
| 8517 | } |
| 8518 | |
| 8519 | for (i = 0; i < size; i++) { |
| 8520 | pages[i] = alloc_page(gfp_flags); |
| 8521 | if (!pages[i]) { |
| 8522 | dprintk("%s: failed to allocate page\n", __func__); |
| 8523 | nfs4_free_pages(pages, size); |
| 8524 | return NULL; |
| 8525 | } |
| 8526 | } |
| 8527 | |
| 8528 | return pages; |
| 8529 | } |
| 8530 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8531 | static void nfs4_layoutget_release(void *calldata) |
| 8532 | { |
| 8533 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8534 | struct inode *inode = lgp->args.inode; |
| 8535 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8536 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8537 | |
| 8538 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8539 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8540 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8541 | put_nfs_open_context(lgp->args.ctx); |
| 8542 | kfree(calldata); |
| 8543 | dprintk("<-- %s\n", __func__); |
| 8544 | } |
| 8545 | |
| 8546 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8547 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8548 | .rpc_call_done = nfs4_layoutget_done, |
| 8549 | .rpc_release = nfs4_layoutget_release, |
| 8550 | }; |
| 8551 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8552 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8553 | 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] | 8554 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8555 | struct inode *inode = lgp->args.inode; |
| 8556 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8557 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8558 | struct rpc_task *task; |
| 8559 | struct rpc_message msg = { |
| 8560 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8561 | .rpc_argp = &lgp->args, |
| 8562 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8563 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8564 | }; |
| 8565 | struct rpc_task_setup task_setup_data = { |
| 8566 | .rpc_client = server->client, |
| 8567 | .rpc_message = &msg, |
| 8568 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8569 | .callback_data = lgp, |
| 8570 | .flags = RPC_TASK_ASYNC, |
| 8571 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8572 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8573 | struct nfs4_exception exception = { |
| 8574 | .inode = inode, |
| 8575 | .timeout = *timeout, |
| 8576 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8577 | int status = 0; |
| 8578 | |
| 8579 | dprintk("--> %s\n", __func__); |
| 8580 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8581 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8582 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8583 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8584 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8585 | if (!lgp->args.layout.pages) { |
| 8586 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8587 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8588 | } |
| 8589 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8590 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8591 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8592 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8593 | 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] | 8594 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8595 | task = rpc_run_task(&task_setup_data); |
| 8596 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8597 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8598 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8599 | if (status == 0) { |
| 8600 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8601 | *timeout = exception.timeout; |
| 8602 | } |
| 8603 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8604 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8605 | &lgp->args.range, |
| 8606 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8607 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8608 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8609 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8610 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8611 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8612 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8613 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8614 | rpc_put_task(task); |
| 8615 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8616 | if (status) |
| 8617 | return ERR_PTR(status); |
| 8618 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8619 | } |
| 8620 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8621 | static void |
| 8622 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8623 | { |
| 8624 | struct nfs4_layoutreturn *lrp = calldata; |
| 8625 | |
| 8626 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8627 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8628 | &lrp->args.seq_args, |
| 8629 | &lrp->res.seq_res, |
| 8630 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8631 | } |
| 8632 | |
| 8633 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8634 | { |
| 8635 | struct nfs4_layoutreturn *lrp = calldata; |
| 8636 | struct nfs_server *server; |
| 8637 | |
| 8638 | dprintk("--> %s\n", __func__); |
| 8639 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8640 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8641 | return; |
| 8642 | |
| 8643 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8644 | switch (task->tk_status) { |
| 8645 | default: |
| 8646 | task->tk_status = 0; |
| 8647 | case 0: |
| 8648 | break; |
| 8649 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8650 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8651 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8652 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8653 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8654 | return; |
| 8655 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8656 | dprintk("<-- %s\n", __func__); |
| 8657 | } |
| 8658 | |
| 8659 | static void nfs4_layoutreturn_release(void *calldata) |
| 8660 | { |
| 8661 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8662 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8663 | |
| 8664 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8665 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8666 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8667 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8668 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8669 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8670 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8671 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8672 | kfree(calldata); |
| 8673 | dprintk("<-- %s\n", __func__); |
| 8674 | } |
| 8675 | |
| 8676 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8677 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8678 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8679 | .rpc_release = nfs4_layoutreturn_release, |
| 8680 | }; |
| 8681 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8682 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8683 | { |
| 8684 | struct rpc_task *task; |
| 8685 | struct rpc_message msg = { |
| 8686 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8687 | .rpc_argp = &lrp->args, |
| 8688 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8689 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8690 | }; |
| 8691 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8692 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8693 | .rpc_message = &msg, |
| 8694 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8695 | .callback_data = lrp, |
| 8696 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8697 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8698 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8699 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8700 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8701 | &task_setup_data.rpc_client, &msg); |
| 8702 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8703 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8704 | if (!sync) { |
| 8705 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8706 | if (!lrp->inode) { |
| 8707 | nfs4_layoutreturn_release(lrp); |
| 8708 | return -EAGAIN; |
| 8709 | } |
| 8710 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8711 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8712 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8713 | task = rpc_run_task(&task_setup_data); |
| 8714 | if (IS_ERR(task)) |
| 8715 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8716 | if (sync) |
| 8717 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8718 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8719 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8720 | rpc_put_task(task); |
| 8721 | return status; |
| 8722 | } |
| 8723 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8724 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8725 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8726 | struct pnfs_device *pdev, |
| 8727 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8728 | { |
| 8729 | struct nfs4_getdeviceinfo_args args = { |
| 8730 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8731 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8732 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8733 | }; |
| 8734 | struct nfs4_getdeviceinfo_res res = { |
| 8735 | .pdev = pdev, |
| 8736 | }; |
| 8737 | struct rpc_message msg = { |
| 8738 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8739 | .rpc_argp = &args, |
| 8740 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8741 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8742 | }; |
| 8743 | int status; |
| 8744 | |
| 8745 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8746 | 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] | 8747 | if (res.notification & ~args.notify_types) |
| 8748 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8749 | if (res.notification != args.notify_types) |
| 8750 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8751 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8752 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8753 | |
| 8754 | return status; |
| 8755 | } |
| 8756 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8757 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8758 | struct pnfs_device *pdev, |
| 8759 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8760 | { |
| 8761 | struct nfs4_exception exception = { }; |
| 8762 | int err; |
| 8763 | |
| 8764 | do { |
| 8765 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8766 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8767 | &exception); |
| 8768 | } while (exception.retry); |
| 8769 | return err; |
| 8770 | } |
| 8771 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8772 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8773 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8774 | { |
| 8775 | struct nfs4_layoutcommit_data *data = calldata; |
| 8776 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8777 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8778 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8779 | &data->args.seq_args, |
| 8780 | &data->res.seq_res, |
| 8781 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | static void |
| 8785 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8786 | { |
| 8787 | struct nfs4_layoutcommit_data *data = calldata; |
| 8788 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8789 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8790 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8791 | return; |
| 8792 | |
| 8793 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8794 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8795 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8796 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8797 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8798 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8799 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8800 | break; |
| 8801 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8802 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8803 | rpc_restart_call_prepare(task); |
| 8804 | return; |
| 8805 | } |
| 8806 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8807 | } |
| 8808 | |
| 8809 | static void nfs4_layoutcommit_release(void *calldata) |
| 8810 | { |
| 8811 | struct nfs4_layoutcommit_data *data = calldata; |
| 8812 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8813 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8814 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8815 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8816 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8817 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8818 | kfree(data); |
| 8819 | } |
| 8820 | |
| 8821 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8822 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8823 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8824 | .rpc_release = nfs4_layoutcommit_release, |
| 8825 | }; |
| 8826 | |
| 8827 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8828 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8829 | { |
| 8830 | struct rpc_message msg = { |
| 8831 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8832 | .rpc_argp = &data->args, |
| 8833 | .rpc_resp = &data->res, |
| 8834 | .rpc_cred = data->cred, |
| 8835 | }; |
| 8836 | struct rpc_task_setup task_setup_data = { |
| 8837 | .task = &data->task, |
| 8838 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8839 | .rpc_message = &msg, |
| 8840 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8841 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8842 | }; |
| 8843 | struct rpc_task *task; |
| 8844 | int status = 0; |
| 8845 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8846 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8847 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8848 | data->args.lastbytewritten, |
| 8849 | data->args.inode->i_ino); |
| 8850 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8851 | if (!sync) { |
| 8852 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8853 | if (data->inode == NULL) { |
| 8854 | nfs4_layoutcommit_release(data); |
| 8855 | return -EAGAIN; |
| 8856 | } |
| 8857 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8858 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8859 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8860 | task = rpc_run_task(&task_setup_data); |
| 8861 | if (IS_ERR(task)) |
| 8862 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8863 | if (sync) |
| 8864 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8865 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8866 | dprintk("%s: status %d\n", __func__, status); |
| 8867 | rpc_put_task(task); |
| 8868 | return status; |
| 8869 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8870 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8871 | /** |
| 8872 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8873 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8874 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8875 | static int |
| 8876 | _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] | 8877 | struct nfs_fsinfo *info, |
| 8878 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8879 | { |
| 8880 | struct nfs41_secinfo_no_name_args args = { |
| 8881 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8882 | }; |
| 8883 | struct nfs4_secinfo_res res = { |
| 8884 | .flavors = flavors, |
| 8885 | }; |
| 8886 | struct rpc_message msg = { |
| 8887 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8888 | .rpc_argp = &args, |
| 8889 | .rpc_resp = &res, |
| 8890 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8891 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8892 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8893 | int status; |
| 8894 | |
| 8895 | if (use_integrity) { |
| 8896 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8897 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8898 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8899 | } |
| 8900 | |
| 8901 | dprintk("--> %s\n", __func__); |
| 8902 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8903 | &res.seq_res, 0); |
| 8904 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8905 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8906 | if (cred) |
| 8907 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8908 | |
| 8909 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8910 | } |
| 8911 | |
| 8912 | static int |
| 8913 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8914 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8915 | { |
| 8916 | struct nfs4_exception exception = { }; |
| 8917 | int err; |
| 8918 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8919 | /* first try using integrity protection */ |
| 8920 | err = -NFS4ERR_WRONGSEC; |
| 8921 | |
| 8922 | /* try to use integrity protection with machine cred */ |
| 8923 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8924 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8925 | flavors, true); |
| 8926 | |
| 8927 | /* |
| 8928 | * if unable to use integrity protection, or SECINFO with |
| 8929 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8930 | * disallowed by spec, but exists in deployed servers) use |
| 8931 | * the current filesystem's rpc_client and the user cred. |
| 8932 | */ |
| 8933 | if (err == -NFS4ERR_WRONGSEC) |
| 8934 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8935 | flavors, false); |
| 8936 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8937 | switch (err) { |
| 8938 | case 0: |
| 8939 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8940 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8941 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8942 | default: |
| 8943 | err = nfs4_handle_exception(server, err, &exception); |
| 8944 | } |
| 8945 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8946 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8947 | return err; |
| 8948 | } |
| 8949 | |
| 8950 | static int |
| 8951 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8952 | struct nfs_fsinfo *info) |
| 8953 | { |
| 8954 | int err; |
| 8955 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8956 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8957 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8958 | struct nfs4_secinfo4 *secinfo; |
| 8959 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8960 | |
| 8961 | page = alloc_page(GFP_KERNEL); |
| 8962 | if (!page) { |
| 8963 | err = -ENOMEM; |
| 8964 | goto out; |
| 8965 | } |
| 8966 | |
| 8967 | flavors = page_address(page); |
| 8968 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8969 | |
| 8970 | /* |
| 8971 | * Fall back on "guess and check" method if |
| 8972 | * the server doesn't support SECINFO_NO_NAME |
| 8973 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8974 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8975 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8976 | goto out_freepage; |
| 8977 | } |
| 8978 | if (err) |
| 8979 | goto out_freepage; |
| 8980 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8981 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8982 | secinfo = &flavors->flavors[i]; |
| 8983 | |
| 8984 | switch (secinfo->flavor) { |
| 8985 | case RPC_AUTH_NULL: |
| 8986 | case RPC_AUTH_UNIX: |
| 8987 | case RPC_AUTH_GSS: |
| 8988 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8989 | &secinfo->flavor_info); |
| 8990 | break; |
| 8991 | default: |
| 8992 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8993 | break; |
| 8994 | } |
| 8995 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8996 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8997 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8998 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8999 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9000 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9001 | info, flavor); |
| 9002 | if (!err) |
| 9003 | break; |
| 9004 | } |
| 9005 | } |
| 9006 | |
| 9007 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9008 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9009 | |
| 9010 | out_freepage: |
| 9011 | put_page(page); |
| 9012 | if (err == -EACCES) |
| 9013 | return -EPERM; |
| 9014 | out: |
| 9015 | return err; |
| 9016 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9017 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9018 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9019 | nfs4_stateid *stateid, |
| 9020 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9021 | { |
| 9022 | int status; |
| 9023 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9024 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9025 | }; |
| 9026 | struct nfs41_test_stateid_res res; |
| 9027 | struct rpc_message msg = { |
| 9028 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9029 | .rpc_argp = &args, |
| 9030 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9031 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9032 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9033 | struct rpc_clnt *rpc_client = server->client; |
| 9034 | |
| 9035 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9036 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9037 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9038 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9039 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9040 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9041 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9042 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9043 | if (status != NFS_OK) { |
| 9044 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9045 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9046 | } |
| 9047 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9048 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9049 | } |
| 9050 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9051 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9052 | int err, struct nfs4_exception *exception) |
| 9053 | { |
| 9054 | exception->retry = 0; |
| 9055 | switch(err) { |
| 9056 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9057 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9058 | nfs4_handle_exception(server, err, exception); |
| 9059 | break; |
| 9060 | case -NFS4ERR_BADSESSION: |
| 9061 | case -NFS4ERR_BADSLOT: |
| 9062 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9063 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9064 | case -NFS4ERR_DEADSESSION: |
| 9065 | nfs4_do_handle_exception(server, err, exception); |
| 9066 | } |
| 9067 | } |
| 9068 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9069 | /** |
| 9070 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9071 | * |
| 9072 | * @server: server / transport on which to perform the operation |
| 9073 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9074 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9075 | * |
| 9076 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9077 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9078 | * failed or the state ID is not currently valid. |
| 9079 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9080 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9081 | nfs4_stateid *stateid, |
| 9082 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9083 | { |
| 9084 | struct nfs4_exception exception = { }; |
| 9085 | int err; |
| 9086 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9087 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9088 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9089 | } while (exception.retry); |
| 9090 | return err; |
| 9091 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9092 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9093 | struct nfs_free_stateid_data { |
| 9094 | struct nfs_server *server; |
| 9095 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9096 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9097 | }; |
| 9098 | |
| 9099 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9100 | { |
| 9101 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9102 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9103 | &data->args.seq_args, |
| 9104 | &data->res.seq_res, |
| 9105 | task); |
| 9106 | } |
| 9107 | |
| 9108 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9109 | { |
| 9110 | struct nfs_free_stateid_data *data = calldata; |
| 9111 | |
| 9112 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9113 | |
| 9114 | switch (task->tk_status) { |
| 9115 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9116 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9117 | rpc_restart_call_prepare(task); |
| 9118 | } |
| 9119 | } |
| 9120 | |
| 9121 | static void nfs41_free_stateid_release(void *calldata) |
| 9122 | { |
| 9123 | kfree(calldata); |
| 9124 | } |
| 9125 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9126 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9127 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9128 | .rpc_call_done = nfs41_free_stateid_done, |
| 9129 | .rpc_release = nfs41_free_stateid_release, |
| 9130 | }; |
| 9131 | |
| 9132 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9133 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9134 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9135 | bool privileged) |
| 9136 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9137 | struct rpc_message msg = { |
| 9138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9139 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9140 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9141 | struct rpc_task_setup task_setup = { |
| 9142 | .rpc_client = server->client, |
| 9143 | .rpc_message = &msg, |
| 9144 | .callback_ops = &nfs41_free_stateid_ops, |
| 9145 | .flags = RPC_TASK_ASYNC, |
| 9146 | }; |
| 9147 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9148 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9149 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9150 | &task_setup.rpc_client, &msg); |
| 9151 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9152 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9153 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9154 | if (!data) |
| 9155 | return ERR_PTR(-ENOMEM); |
| 9156 | data->server = server; |
| 9157 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9158 | |
| 9159 | task_setup.callback_data = data; |
| 9160 | |
| 9161 | msg.rpc_argp = &data->args; |
| 9162 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9163 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9164 | if (privileged) |
| 9165 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9166 | |
| 9167 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9168 | } |
| 9169 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9170 | /** |
| 9171 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9172 | * |
| 9173 | * @server: server / transport on which to perform the operation |
| 9174 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9175 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9176 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9177 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9178 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9179 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9180 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9181 | const nfs4_stateid *stateid, |
| 9182 | struct rpc_cred *cred, |
| 9183 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9184 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9185 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9186 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9187 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9188 | if (IS_ERR(task)) |
| 9189 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9190 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9191 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9192 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9193 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9194 | static void |
| 9195 | 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] | 9196 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9197 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9198 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9199 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9200 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9201 | } |
| 9202 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9203 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9204 | const nfs4_stateid *s2) |
| 9205 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9206 | if (s1->type != s2->type) |
| 9207 | return false; |
| 9208 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9209 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9210 | return false; |
| 9211 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9212 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9213 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9214 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9215 | return true; |
| 9216 | |
| 9217 | return false; |
| 9218 | } |
| 9219 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9220 | #endif /* CONFIG_NFS_V4_1 */ |
| 9221 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9222 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9223 | const nfs4_stateid *s2) |
| 9224 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9225 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9226 | } |
| 9227 | |
| 9228 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9229 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9230 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9231 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9232 | .recover_open = nfs4_open_reclaim, |
| 9233 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9234 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9235 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9236 | }; |
| 9237 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9238 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9239 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9240 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9241 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9242 | .recover_open = nfs4_open_reclaim, |
| 9243 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9244 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9245 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9246 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9247 | }; |
| 9248 | #endif /* CONFIG_NFS_V4_1 */ |
| 9249 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9250 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9251 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9252 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9253 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9254 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9255 | .establish_clid = nfs4_init_clientid, |
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_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9260 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9261 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9262 | .recover_open = nfs41_open_expired, |
| 9263 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9264 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9265 | }; |
| 9266 | #endif /* CONFIG_NFS_V4_1 */ |
| 9267 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9268 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9269 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9270 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9271 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9272 | }; |
| 9273 | |
| 9274 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9275 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9276 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9277 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9278 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9279 | }; |
| 9280 | #endif |
| 9281 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9282 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9283 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9284 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9285 | }; |
| 9286 | |
| 9287 | #if defined(CONFIG_NFS_V4_1) |
| 9288 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9289 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9290 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9291 | }; |
| 9292 | #endif /* CONFIG_NFS_V4_1 */ |
| 9293 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9294 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9295 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9296 | .init_caps = NFS_CAP_READDIRPLUS |
| 9297 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9298 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9299 | .init_client = nfs40_init_client, |
| 9300 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9301 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9302 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9303 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9304 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9305 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9306 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9307 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9308 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9309 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9310 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9311 | }; |
| 9312 | |
| 9313 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9314 | static struct nfs_seqid * |
| 9315 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9316 | { |
| 9317 | return NULL; |
| 9318 | } |
| 9319 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9320 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9321 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9322 | .init_caps = NFS_CAP_READDIRPLUS |
| 9323 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9324 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9325 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9326 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9327 | .init_client = nfs41_init_client, |
| 9328 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9329 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9330 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9331 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9332 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9333 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9334 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9335 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9336 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9337 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9338 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9339 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9340 | }; |
| 9341 | #endif |
| 9342 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9343 | #if defined(CONFIG_NFS_V4_2) |
| 9344 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9345 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9346 | .init_caps = NFS_CAP_READDIRPLUS |
| 9347 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9348 | | NFS_CAP_POSIX_LOCK |
| 9349 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9350 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9351 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9352 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9353 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9354 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9355 | | NFS_CAP_LAYOUTSTATS |
| 9356 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9357 | .init_client = nfs41_init_client, |
| 9358 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9359 | .match_stateid = nfs41_match_stateid, |
| 9360 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9361 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9362 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9363 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9364 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9365 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9366 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9367 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9368 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9369 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9370 | }; |
| 9371 | #endif |
| 9372 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9373 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9374 | [0] = &nfs_v4_0_minor_ops, |
| 9375 | #if defined(CONFIG_NFS_V4_1) |
| 9376 | [1] = &nfs_v4_1_minor_ops, |
| 9377 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9378 | #if defined(CONFIG_NFS_V4_2) |
| 9379 | [2] = &nfs_v4_2_minor_ops, |
| 9380 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9381 | }; |
| 9382 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9383 | 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] | 9384 | { |
| 9385 | ssize_t error, error2; |
| 9386 | |
| 9387 | error = generic_listxattr(dentry, list, size); |
| 9388 | if (error < 0) |
| 9389 | return error; |
| 9390 | if (list) { |
| 9391 | list += error; |
| 9392 | size -= error; |
| 9393 | } |
| 9394 | |
| 9395 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9396 | if (error2 < 0) |
| 9397 | return error2; |
| 9398 | return error + error2; |
| 9399 | } |
| 9400 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9401 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9402 | .create = nfs_create, |
| 9403 | .lookup = nfs_lookup, |
| 9404 | .atomic_open = nfs_atomic_open, |
| 9405 | .link = nfs_link, |
| 9406 | .unlink = nfs_unlink, |
| 9407 | .symlink = nfs_symlink, |
| 9408 | .mkdir = nfs_mkdir, |
| 9409 | .rmdir = nfs_rmdir, |
| 9410 | .mknod = nfs_mknod, |
| 9411 | .rename = nfs_rename, |
| 9412 | .permission = nfs_permission, |
| 9413 | .getattr = nfs_getattr, |
| 9414 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9415 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9416 | }; |
| 9417 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9418 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9419 | .permission = nfs_permission, |
| 9420 | .getattr = nfs_getattr, |
| 9421 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9422 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9423 | }; |
| 9424 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9425 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9426 | .version = 4, /* protocol version */ |
| 9427 | .dentry_ops = &nfs4_dentry_operations, |
| 9428 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9429 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9430 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9431 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9432 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9433 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9434 | .getattr = nfs4_proc_getattr, |
| 9435 | .setattr = nfs4_proc_setattr, |
| 9436 | .lookup = nfs4_proc_lookup, |
| 9437 | .access = nfs4_proc_access, |
| 9438 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9439 | .create = nfs4_proc_create, |
| 9440 | .remove = nfs4_proc_remove, |
| 9441 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9442 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9443 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9444 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9445 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9446 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9447 | .link = nfs4_proc_link, |
| 9448 | .symlink = nfs4_proc_symlink, |
| 9449 | .mkdir = nfs4_proc_mkdir, |
| 9450 | .rmdir = nfs4_proc_remove, |
| 9451 | .readdir = nfs4_proc_readdir, |
| 9452 | .mknod = nfs4_proc_mknod, |
| 9453 | .statfs = nfs4_proc_statfs, |
| 9454 | .fsinfo = nfs4_proc_fsinfo, |
| 9455 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9456 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9457 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9458 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9459 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9460 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9461 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9462 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9463 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9464 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9465 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9466 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9467 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9468 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9469 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9470 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9471 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9472 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9473 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9474 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9475 | .create_server = nfs4_create_server, |
| 9476 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9477 | }; |
| 9478 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9479 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9480 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9481 | .list = nfs4_xattr_list_nfs4_acl, |
| 9482 | .get = nfs4_xattr_get_nfs4_acl, |
| 9483 | .set = nfs4_xattr_set_nfs4_acl, |
| 9484 | }; |
| 9485 | |
| 9486 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9487 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9488 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9489 | &nfs4_xattr_nfs4_label_handler, |
| 9490 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9491 | NULL |
| 9492 | }; |
| 9493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9494 | /* |
| 9495 | * Local variables: |
| 9496 | * c-basic-offset: 8 |
| 9497 | * End: |
| 9498 | */ |