Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 58 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 60 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 61 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 62 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 63 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 64 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 65 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 76 | /* file attributes which can be mapped to nfs attributes */ |
| 77 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 78 | | ATTR_UID \ |
| 79 | | ATTR_GID \ |
| 80 | | ATTR_SIZE \ |
| 81 | | ATTR_ATIME \ |
| 82 | | ATTR_MTIME \ |
| 83 | | ATTR_CTIME \ |
| 84 | | ATTR_ATIME_SET \ |
| 85 | | ATTR_MTIME_SET) |
| 86 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 87 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 88 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 89 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 91 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 92 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 93 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 94 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 95 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 96 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 98 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 99 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 100 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 101 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 102 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 103 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 106 | static inline struct nfs4_label * |
| 107 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 108 | struct iattr *sattr, struct nfs4_label *label) |
| 109 | { |
| 110 | int err; |
| 111 | |
| 112 | if (label == NULL) |
| 113 | return NULL; |
| 114 | |
| 115 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 116 | return NULL; |
| 117 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 118 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 119 | &dentry->d_name, (void **)&label->label, &label->len); |
| 120 | if (err == 0) |
| 121 | return label; |
| 122 | |
| 123 | return NULL; |
| 124 | } |
| 125 | static inline void |
| 126 | nfs4_label_release_security(struct nfs4_label *label) |
| 127 | { |
| 128 | if (label) |
| 129 | security_release_secctx(label->label, label->len); |
| 130 | } |
| 131 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | return server->attr_bitmask; |
| 135 | |
| 136 | return server->attr_bitmask_nl; |
| 137 | } |
| 138 | #else |
| 139 | static inline struct nfs4_label * |
| 140 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 141 | struct iattr *sattr, struct nfs4_label *l) |
| 142 | { return NULL; } |
| 143 | static inline void |
| 144 | nfs4_label_release_security(struct nfs4_label *label) |
| 145 | { return; } |
| 146 | static inline u32 * |
| 147 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 148 | { return server->attr_bitmask; } |
| 149 | #endif |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 152 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 154 | if (err >= -1000) |
| 155 | return err; |
| 156 | switch (err) { |
| 157 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 158 | case -NFS4ERR_LAYOUTTRYLATER: |
| 159 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 161 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 162 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 163 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 164 | case -NFS4ERR_BADOWNER: |
| 165 | case -NFS4ERR_BADNAME: |
| 166 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 167 | case -NFS4ERR_SHARE_DENIED: |
| 168 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 169 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 170 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 171 | case -NFS4ERR_FILE_OPEN: |
| 172 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 175 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 176 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This is our standard bitmap for GETATTR requests. |
| 183 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 184 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID, |
| 190 | FATTR4_WORD1_MODE |
| 191 | | FATTR4_WORD1_NUMLINKS |
| 192 | | FATTR4_WORD1_OWNER |
| 193 | | FATTR4_WORD1_OWNER_GROUP |
| 194 | | FATTR4_WORD1_RAWDEV |
| 195 | | FATTR4_WORD1_SPACE_USED |
| 196 | | FATTR4_WORD1_TIME_ACCESS |
| 197 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 198 | | FATTR4_WORD1_TIME_MODIFY |
| 199 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 200 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 201 | FATTR4_WORD2_SECURITY_LABEL |
| 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 205 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 206 | FATTR4_WORD0_TYPE |
| 207 | | FATTR4_WORD0_CHANGE |
| 208 | | FATTR4_WORD0_SIZE |
| 209 | | FATTR4_WORD0_FSID |
| 210 | | FATTR4_WORD0_FILEID, |
| 211 | FATTR4_WORD1_MODE |
| 212 | | FATTR4_WORD1_NUMLINKS |
| 213 | | FATTR4_WORD1_OWNER |
| 214 | | FATTR4_WORD1_OWNER_GROUP |
| 215 | | FATTR4_WORD1_RAWDEV |
| 216 | | FATTR4_WORD1_SPACE_USED |
| 217 | | FATTR4_WORD1_TIME_ACCESS |
| 218 | | FATTR4_WORD1_TIME_METADATA |
| 219 | | FATTR4_WORD1_TIME_MODIFY, |
| 220 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 221 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 222 | | FATTR4_WORD2_SECURITY_LABEL |
| 223 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 226 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 227 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 228 | | FATTR4_WORD0_FILEID, |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_FILES_AVAIL |
| 233 | | FATTR4_WORD0_FILES_FREE |
| 234 | | FATTR4_WORD0_FILES_TOTAL, |
| 235 | FATTR4_WORD1_SPACE_AVAIL |
| 236 | | FATTR4_WORD1_SPACE_FREE |
| 237 | | FATTR4_WORD1_SPACE_TOTAL |
| 238 | }; |
| 239 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 240 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | FATTR4_WORD0_MAXLINK |
| 242 | | FATTR4_WORD0_MAXNAME, |
| 243 | 0 |
| 244 | }; |
| 245 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 246 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | | FATTR4_WORD0_MAXREAD |
| 248 | | FATTR4_WORD0_MAXWRITE |
| 249 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 250 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 252 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 253 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 256 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 257 | FATTR4_WORD0_TYPE |
| 258 | | FATTR4_WORD0_CHANGE |
| 259 | | FATTR4_WORD0_SIZE |
| 260 | | FATTR4_WORD0_FSID |
| 261 | | FATTR4_WORD0_FILEID |
| 262 | | FATTR4_WORD0_FS_LOCATIONS, |
| 263 | FATTR4_WORD1_MODE |
| 264 | | FATTR4_WORD1_NUMLINKS |
| 265 | | FATTR4_WORD1_OWNER |
| 266 | | FATTR4_WORD1_OWNER_GROUP |
| 267 | | FATTR4_WORD1_RAWDEV |
| 268 | | FATTR4_WORD1_SPACE_USED |
| 269 | | FATTR4_WORD1_TIME_ACCESS |
| 270 | | FATTR4_WORD1_TIME_METADATA |
| 271 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 272 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | }; |
| 274 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 275 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct nfs4_readdir_arg *readdir) |
| 277 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 278 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 281 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | readdir->cookie = 0; |
| 287 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 288 | if (cookie == 2) |
| 289 | return; |
| 290 | |
| 291 | /* |
| 292 | * NFSv4 servers do not return entries for '.' and '..' |
| 293 | * Therefore, we fake these entries here. We let '.' |
| 294 | * have cookie 0 and '..' have cookie 1. Note that |
| 295 | * when talking to the server, we always send cookie 0 |
| 296 | * instead of 1 or 2. |
| 297 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 298 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | if (cookie == 0) { |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_one; /* cookie, second word */ |
| 304 | *p++ = xdr_one; /* entry len */ |
| 305 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | *p++ = xdr_one; /* next */ |
| 314 | *p++ = xdr_zero; /* cookie, first word */ |
| 315 | *p++ = xdr_two; /* cookie, second word */ |
| 316 | *p++ = xdr_two; /* entry len */ |
| 317 | memcpy(p, "..\0\0", 4); /* entry */ |
| 318 | p++; |
| 319 | *p++ = xdr_one; /* bitmap length */ |
| 320 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 321 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 322 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | readdir->pgbase = (char *)p - (char *)start; |
| 325 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 326 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 329 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 330 | nfs4_stateid *stateid, |
| 331 | struct rpc_cred *cred) |
| 332 | { |
| 333 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 334 | |
| 335 | ops->test_and_free_expired(server, stateid, cred); |
| 336 | } |
| 337 | |
| 338 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 339 | nfs4_stateid *stateid, |
| 340 | struct rpc_cred *cred) |
| 341 | { |
| 342 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 343 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 344 | } |
| 345 | |
| 346 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 347 | const nfs4_stateid *stateid, |
| 348 | struct rpc_cred *cred) |
| 349 | { |
| 350 | nfs4_stateid tmp; |
| 351 | |
| 352 | nfs4_stateid_copy(&tmp, stateid); |
| 353 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 354 | } |
| 355 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 356 | static long nfs4_update_delay(long *timeout) |
| 357 | { |
| 358 | long ret; |
| 359 | if (!timeout) |
| 360 | return NFS4_POLL_RETRY_MAX; |
| 361 | if (*timeout <= 0) |
| 362 | *timeout = NFS4_POLL_RETRY_MIN; |
| 363 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 364 | *timeout = NFS4_POLL_RETRY_MAX; |
| 365 | ret = *timeout; |
| 366 | *timeout <<= 1; |
| 367 | return ret; |
| 368 | } |
| 369 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 370 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 371 | { |
| 372 | int res = 0; |
| 373 | |
| 374 | might_sleep(); |
| 375 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 376 | freezable_schedule_timeout_killable_unsafe( |
| 377 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | if (fatal_signal_pending(current)) |
| 379 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | return res; |
| 381 | } |
| 382 | |
| 383 | /* This is the error handling routine for processes that are allowed |
| 384 | * to sleep. |
| 385 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 386 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 387 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 388 | { |
| 389 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 390 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 391 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 393 | int ret = errorcode; |
| 394 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 395 | exception->delay = 0; |
| 396 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 397 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 398 | |
| 399 | if (stateid == NULL && state != NULL) |
| 400 | stateid = &state->stateid; |
| 401 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 402 | switch(errorcode) { |
| 403 | case 0: |
| 404 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 405 | case -NFS4ERR_DELEG_REVOKED: |
| 406 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 407 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 408 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 409 | if (inode != NULL && stateid != NULL) { |
| 410 | nfs_inode_find_state_and_recover(inode, |
| 411 | stateid); |
| 412 | goto wait_on_recovery; |
| 413 | } |
| 414 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 415 | if (inode) { |
| 416 | int err; |
| 417 | |
| 418 | err = nfs_async_inode_return_delegation(inode, |
| 419 | stateid); |
| 420 | if (err == 0) |
| 421 | goto wait_on_recovery; |
| 422 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 423 | exception->retry = 1; |
| 424 | break; |
| 425 | } |
| 426 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 427 | if (state == NULL) |
| 428 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 429 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 430 | if (ret < 0) |
| 431 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 432 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 434 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 435 | nfs4_schedule_lease_recovery(clp); |
| 436 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 437 | case -NFS4ERR_MOVED: |
| 438 | ret = nfs4_schedule_migration_recovery(server); |
| 439 | if (ret < 0) |
| 440 | break; |
| 441 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 442 | case -NFS4ERR_LEASE_MOVED: |
| 443 | nfs4_schedule_lease_moved_recovery(clp); |
| 444 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 445 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 446 | case -NFS4ERR_BADSESSION: |
| 447 | case -NFS4ERR_BADSLOT: |
| 448 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 449 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 450 | case -NFS4ERR_DEADSESSION: |
| 451 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 452 | case -NFS4ERR_SEQ_MISORDERED: |
| 453 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 454 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 455 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 456 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 457 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 458 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 459 | if (exception->timeout > HZ) { |
| 460 | /* We have retried a decent amount, time to |
| 461 | * fail |
| 462 | */ |
| 463 | ret = -EBUSY; |
| 464 | break; |
| 465 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 467 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 468 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 469 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 470 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 471 | exception->delay = 1; |
| 472 | return 0; |
| 473 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 474 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 475 | case -NFS4ERR_OLD_STATEID: |
| 476 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 477 | break; |
| 478 | case -NFS4ERR_BADOWNER: |
| 479 | /* The following works around a Linux server bug! */ |
| 480 | case -NFS4ERR_BADNAME: |
| 481 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 482 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 483 | exception->retry = 1; |
| 484 | printk(KERN_WARNING "NFS: v4 server %s " |
| 485 | "does not accept raw " |
| 486 | "uid/gids. " |
| 487 | "Reenabling the idmapper.\n", |
| 488 | server->nfs_client->cl_hostname); |
| 489 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 490 | } |
| 491 | /* We failed to handle the error */ |
| 492 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 493 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 494 | exception->recovering = 1; |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* This is the error handling routine for processes that are allowed |
| 499 | * to sleep. |
| 500 | */ |
| 501 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 502 | { |
| 503 | struct nfs_client *clp = server->nfs_client; |
| 504 | int ret; |
| 505 | |
| 506 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 507 | if (exception->delay) { |
| 508 | ret = nfs4_delay(server->client, &exception->timeout); |
| 509 | goto out_retry; |
| 510 | } |
| 511 | if (exception->recovering) { |
| 512 | ret = nfs4_wait_clnt_recover(clp); |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | return -EIO; |
| 515 | goto out_retry; |
| 516 | } |
| 517 | return ret; |
| 518 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 519 | if (ret == 0) |
| 520 | exception->retry = 1; |
| 521 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 524 | static int |
| 525 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 526 | int errorcode, struct nfs4_exception *exception) |
| 527 | { |
| 528 | struct nfs_client *clp = server->nfs_client; |
| 529 | int ret; |
| 530 | |
| 531 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 532 | if (exception->delay) { |
| 533 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 534 | goto out_retry; |
| 535 | } |
| 536 | if (exception->recovering) { |
| 537 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 538 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 539 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 540 | goto out_retry; |
| 541 | } |
| 542 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 543 | ret = -EIO; |
| 544 | return ret; |
| 545 | out_retry: |
| 546 | if (ret == 0) |
| 547 | exception->retry = 1; |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | static int |
| 552 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 553 | struct nfs4_state *state, long *timeout) |
| 554 | { |
| 555 | struct nfs4_exception exception = { |
| 556 | .state = state, |
| 557 | }; |
| 558 | |
| 559 | if (task->tk_status >= 0) |
| 560 | return 0; |
| 561 | if (timeout) |
| 562 | exception.timeout = *timeout; |
| 563 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 564 | task->tk_status, |
| 565 | &exception); |
| 566 | if (exception.delay && timeout) |
| 567 | *timeout = exception.timeout; |
| 568 | if (exception.retry) |
| 569 | return -EAGAIN; |
| 570 | return 0; |
| 571 | } |
| 572 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 573 | /* |
| 574 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 575 | * or 'false' otherwise. |
| 576 | */ |
| 577 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 578 | { |
| 579 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 580 | |
| 581 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 582 | flavor == RPC_AUTH_GSS_KRB5P) |
| 583 | return true; |
| 584 | |
| 585 | return false; |
| 586 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 587 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 588 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | spin_lock(&clp->cl_lock); |
| 591 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 592 | clp->cl_last_renewal = timestamp; |
| 593 | spin_unlock(&clp->cl_lock); |
| 594 | } |
| 595 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 596 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 597 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 598 | struct nfs_client *clp = server->nfs_client; |
| 599 | |
| 600 | if (!nfs4_has_session(clp)) |
| 601 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 604 | struct nfs4_call_sync_data { |
| 605 | const struct nfs_server *seq_server; |
| 606 | struct nfs4_sequence_args *seq_args; |
| 607 | struct nfs4_sequence_res *seq_res; |
| 608 | }; |
| 609 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 610 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 611 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 612 | { |
| 613 | args->sa_slot = NULL; |
| 614 | args->sa_cache_this = cache_reply; |
| 615 | args->sa_privileged = 0; |
| 616 | |
| 617 | res->sr_slot = NULL; |
| 618 | } |
| 619 | |
| 620 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 621 | { |
| 622 | args->sa_privileged = 1; |
| 623 | } |
| 624 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 625 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 626 | struct nfs4_sequence_args *args, |
| 627 | struct nfs4_sequence_res *res, |
| 628 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 629 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 630 | struct nfs4_slot *slot; |
| 631 | |
| 632 | /* slot already allocated? */ |
| 633 | if (res->sr_slot != NULL) |
| 634 | goto out_start; |
| 635 | |
| 636 | spin_lock(&tbl->slot_tbl_lock); |
| 637 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 638 | goto out_sleep; |
| 639 | |
| 640 | slot = nfs4_alloc_slot(tbl); |
| 641 | if (IS_ERR(slot)) { |
| 642 | if (slot == ERR_PTR(-ENOMEM)) |
| 643 | task->tk_timeout = HZ >> 2; |
| 644 | goto out_sleep; |
| 645 | } |
| 646 | spin_unlock(&tbl->slot_tbl_lock); |
| 647 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 648 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 649 | args->sa_slot = slot; |
| 650 | res->sr_slot = slot; |
| 651 | |
| 652 | out_start: |
| 653 | rpc_call_start(task); |
| 654 | return 0; |
| 655 | |
| 656 | out_sleep: |
| 657 | if (args->sa_privileged) |
| 658 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 659 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 660 | else |
| 661 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 662 | spin_unlock(&tbl->slot_tbl_lock); |
| 663 | return -EAGAIN; |
| 664 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 665 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 666 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 667 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 668 | { |
| 669 | struct nfs4_slot *slot = res->sr_slot; |
| 670 | struct nfs4_slot_table *tbl; |
| 671 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 672 | tbl = slot->table; |
| 673 | spin_lock(&tbl->slot_tbl_lock); |
| 674 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 675 | nfs4_free_slot(tbl, slot); |
| 676 | spin_unlock(&tbl->slot_tbl_lock); |
| 677 | |
| 678 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static int nfs40_sequence_done(struct rpc_task *task, |
| 682 | struct nfs4_sequence_res *res) |
| 683 | { |
| 684 | if (res->sr_slot != NULL) |
| 685 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 686 | return 1; |
| 687 | } |
| 688 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 689 | #if defined(CONFIG_NFS_V4_1) |
| 690 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 691 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 692 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 693 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 694 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 695 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 696 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 697 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 698 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 699 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 700 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 701 | /* Bump the slot sequence number */ |
| 702 | if (slot->seq_done) |
| 703 | slot->seq_nr++; |
| 704 | slot->seq_done = 0; |
| 705 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 706 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 707 | /* Be nice to the server: try to ensure that the last transmitted |
| 708 | * value for highest_user_slotid <= target_highest_slotid |
| 709 | */ |
| 710 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 711 | send_new_highest_used_slotid = true; |
| 712 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 713 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 714 | send_new_highest_used_slotid = false; |
| 715 | goto out_unlock; |
| 716 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 717 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 718 | |
| 719 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 720 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 721 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 722 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 723 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 724 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 725 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 726 | if (waitqueue_active(&tbl->slot_waitq)) |
| 727 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 730 | static int nfs41_sequence_process(struct rpc_task *task, |
| 731 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 732 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 733 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 734 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 737 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 738 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 739 | if (slot == NULL) |
| 740 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 741 | /* don't increment the sequence number if the task wasn't sent */ |
| 742 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 743 | goto out; |
| 744 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 745 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 746 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 747 | if (slot->interrupted) { |
| 748 | slot->interrupted = 0; |
| 749 | interrupted = true; |
| 750 | } |
| 751 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 752 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 753 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 754 | switch (res->sr_status) { |
| 755 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 756 | /* If previous op on slot was interrupted and we reused |
| 757 | * the seq# and got a reply from the cache, then retry |
| 758 | */ |
| 759 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 760 | ++slot->seq_nr; |
| 761 | goto retry_nowait; |
| 762 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 763 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 764 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 765 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 766 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 767 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 768 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 769 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 770 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 772 | case 1: |
| 773 | /* |
| 774 | * sr_status remains 1 if an RPC level error occurred. |
| 775 | * The server may or may not have processed the sequence |
| 776 | * operation.. |
| 777 | * Mark the slot as having hosted an interrupted RPC call. |
| 778 | */ |
| 779 | slot->interrupted = 1; |
| 780 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 781 | case -NFS4ERR_DELAY: |
| 782 | /* The server detected a resend of the RPC call and |
| 783 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 784 | * of RFC5661. |
| 785 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 786 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 787 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 788 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 789 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 790 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 791 | case -NFS4ERR_BADSLOT: |
| 792 | /* |
| 793 | * The slot id we used was probably retired. Try again |
| 794 | * using a different slot id. |
| 795 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 796 | goto retry_nowait; |
| 797 | case -NFS4ERR_SEQ_MISORDERED: |
| 798 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 799 | * Was the last operation on this sequence interrupted? |
| 800 | * If so, retry after bumping the sequence number. |
| 801 | */ |
| 802 | if (interrupted) { |
| 803 | ++slot->seq_nr; |
| 804 | goto retry_nowait; |
| 805 | } |
| 806 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 807 | * Could this slot have been previously retired? |
| 808 | * If so, then the server may be expecting seq_nr = 1! |
| 809 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 810 | if (slot->seq_nr != 1) { |
| 811 | slot->seq_nr = 1; |
| 812 | goto retry_nowait; |
| 813 | } |
| 814 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 815 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 816 | ++slot->seq_nr; |
| 817 | goto retry_nowait; |
Trond Myklebust | 2cf10cd | 2016-12-04 19:26:40 -0500 | [diff] [blame] | 818 | case -NFS4ERR_DEADSESSION: |
| 819 | case -NFS4ERR_BADSESSION: |
| 820 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 821 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 822 | default: |
| 823 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 824 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 825 | } |
| 826 | out: |
| 827 | /* The session may be reset by one of the error handlers. */ |
| 828 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 829 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 830 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 831 | retry_nowait: |
| 832 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 833 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 834 | task->tk_status = 0; |
| 835 | ret = 0; |
| 836 | } |
| 837 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 839 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | goto out; |
| 841 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 842 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 843 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 844 | |
| 845 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 846 | { |
| 847 | if (!nfs41_sequence_process(task, res)) |
| 848 | return 0; |
| 849 | if (res->sr_slot != NULL) |
| 850 | nfs41_sequence_free_slot(res); |
| 851 | return 1; |
| 852 | |
| 853 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 854 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 855 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 856 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 857 | { |
| 858 | if (res->sr_slot == NULL) |
| 859 | return 1; |
| 860 | if (res->sr_slot->table->session != NULL) |
| 861 | return nfs41_sequence_process(task, res); |
| 862 | return nfs40_sequence_done(task, res); |
| 863 | } |
| 864 | |
| 865 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 866 | { |
| 867 | if (res->sr_slot != NULL) { |
| 868 | if (res->sr_slot->table->session != NULL) |
| 869 | nfs41_sequence_free_slot(res); |
| 870 | else |
| 871 | nfs40_sequence_free_slot(res); |
| 872 | } |
| 873 | } |
| 874 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 875 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 876 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 877 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 878 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 879 | if (!res->sr_slot->table->session) |
| 880 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 881 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 882 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 883 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 884 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 885 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 886 | struct nfs4_sequence_args *args, |
| 887 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 888 | struct rpc_task *task) |
| 889 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 890 | struct nfs4_slot *slot; |
| 891 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 892 | |
| 893 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 894 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 895 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 896 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 898 | tbl = &session->fc_slot_table; |
| 899 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 900 | task->tk_timeout = 0; |
| 901 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 902 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 903 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 904 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 905 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 906 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 907 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 908 | } |
| 909 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 910 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 911 | if (IS_ERR(slot)) { |
| 912 | /* If out of memory, try again in 1/4 second */ |
| 913 | if (slot == ERR_PTR(-ENOMEM)) |
| 914 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 915 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 916 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 917 | } |
| 918 | spin_unlock(&tbl->slot_tbl_lock); |
| 919 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 920 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 921 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 922 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 923 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 924 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 925 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 926 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 927 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 928 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 929 | /* |
| 930 | * sr_status is only set in decode_sequence, and so will remain |
| 931 | * set to 1 if an rpc level failure occurs. |
| 932 | */ |
| 933 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 934 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 935 | out_success: |
| 936 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 937 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 938 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 939 | /* Privileged tasks are queued with top priority */ |
| 940 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 941 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 942 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 943 | else |
| 944 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 945 | spin_unlock(&tbl->slot_tbl_lock); |
| 946 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 948 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 949 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 950 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 951 | struct nfs4_sequence_args *args, |
| 952 | struct nfs4_sequence_res *res, |
| 953 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 954 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 955 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 956 | int ret = 0; |
| 957 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 958 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 959 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 960 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 961 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 962 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 963 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 964 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 965 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 966 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 967 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 968 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 969 | return ret; |
| 970 | } |
| 971 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 972 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 973 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 974 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 975 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 976 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 977 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 978 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 979 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 980 | } |
| 981 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 983 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 984 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 985 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 986 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 989 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 990 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 991 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 992 | }; |
| 993 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 994 | #else /* !CONFIG_NFS_V4_1 */ |
| 995 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 996 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 997 | struct nfs4_sequence_args *args, |
| 998 | struct nfs4_sequence_res *res, |
| 999 | struct rpc_task *task) |
| 1000 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1001 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 1002 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 1003 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1004 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1005 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1006 | { |
| 1007 | return nfs40_sequence_done(task, res); |
| 1008 | } |
| 1009 | |
| 1010 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1011 | { |
| 1012 | if (res->sr_slot != NULL) |
| 1013 | nfs40_sequence_free_slot(res); |
| 1014 | } |
| 1015 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1016 | int nfs4_sequence_done(struct rpc_task *task, |
| 1017 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1018 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1019 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1020 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1021 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1022 | |
| 1023 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1024 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1025 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1026 | { |
| 1027 | struct nfs4_call_sync_data *data = calldata; |
| 1028 | nfs4_setup_sequence(data->seq_server, |
| 1029 | data->seq_args, data->seq_res, task); |
| 1030 | } |
| 1031 | |
| 1032 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1033 | { |
| 1034 | struct nfs4_call_sync_data *data = calldata; |
| 1035 | nfs4_sequence_done(task, data->seq_res); |
| 1036 | } |
| 1037 | |
| 1038 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1039 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1040 | .rpc_call_done = nfs40_call_sync_done, |
| 1041 | }; |
| 1042 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1043 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1044 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1046 | struct nfs4_sequence_args *args, |
| 1047 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1048 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1049 | int ret; |
| 1050 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1051 | struct nfs_client *clp = server->nfs_client; |
| 1052 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1053 | .seq_server = server, |
| 1054 | .seq_args = args, |
| 1055 | .seq_res = res, |
| 1056 | }; |
| 1057 | struct rpc_task_setup task_setup = { |
| 1058 | .rpc_client = clnt, |
| 1059 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1060 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1061 | .callback_data = &data |
| 1062 | }; |
| 1063 | |
| 1064 | task = rpc_run_task(&task_setup); |
| 1065 | if (IS_ERR(task)) |
| 1066 | ret = PTR_ERR(task); |
| 1067 | else { |
| 1068 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1069 | rpc_put_task(task); |
| 1070 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1071 | return ret; |
| 1072 | } |
| 1073 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1074 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1075 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1076 | struct rpc_message *msg, |
| 1077 | struct nfs4_sequence_args *args, |
| 1078 | struct nfs4_sequence_res *res, |
| 1079 | int cache_reply) |
| 1080 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1081 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1082 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1086 | { |
| 1087 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1088 | |
| 1089 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1090 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1091 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1092 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1093 | nfsi->attrtimeo_timestamp = jiffies; |
| 1094 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1096 | if (cinfo->before != dir->i_version) |
| 1097 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1098 | NFS_INO_INVALID_ACL; |
| 1099 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1100 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1101 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1102 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | spin_unlock(&dir->i_lock); |
| 1104 | } |
| 1105 | |
| 1106 | struct nfs4_opendata { |
| 1107 | struct kref kref; |
| 1108 | struct nfs_openargs o_arg; |
| 1109 | struct nfs_openres o_res; |
| 1110 | struct nfs_open_confirmargs c_arg; |
| 1111 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1112 | struct nfs4_string owner_name; |
| 1113 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1114 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1116 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1118 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | struct nfs4_state_owner *owner; |
| 1120 | struct nfs4_state *state; |
| 1121 | struct iattr attrs; |
| 1122 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1123 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1124 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1125 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1126 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | int cancelled; |
| 1128 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1129 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1130 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1131 | int err, struct nfs4_exception *exception) |
| 1132 | { |
| 1133 | if (err != -EINVAL) |
| 1134 | return false; |
| 1135 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1136 | return false; |
| 1137 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1138 | exception->retry = 1; |
| 1139 | return true; |
| 1140 | } |
| 1141 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1142 | static u32 |
| 1143 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1144 | fmode_t fmode, int openflags) |
| 1145 | { |
| 1146 | u32 res = 0; |
| 1147 | |
| 1148 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1149 | case FMODE_READ: |
| 1150 | res = NFS4_SHARE_ACCESS_READ; |
| 1151 | break; |
| 1152 | case FMODE_WRITE: |
| 1153 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1154 | break; |
| 1155 | case FMODE_READ|FMODE_WRITE: |
| 1156 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1157 | } |
| 1158 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1159 | goto out; |
| 1160 | /* Want no delegation if we're using O_DIRECT */ |
| 1161 | if (openflags & O_DIRECT) |
| 1162 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1163 | out: |
| 1164 | return res; |
| 1165 | } |
| 1166 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1167 | static enum open_claim_type4 |
| 1168 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1169 | enum open_claim_type4 claim) |
| 1170 | { |
| 1171 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1172 | return claim; |
| 1173 | switch (claim) { |
| 1174 | default: |
| 1175 | return claim; |
| 1176 | case NFS4_OPEN_CLAIM_FH: |
| 1177 | return NFS4_OPEN_CLAIM_NULL; |
| 1178 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1179 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1180 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1181 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1182 | } |
| 1183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
| 1185 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1186 | { |
| 1187 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1188 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | p->o_res.seqid = p->o_arg.seqid; |
| 1190 | p->c_res.seqid = p->c_arg.seqid; |
| 1191 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1192 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1194 | 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] | 1195 | } |
| 1196 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1197 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1198 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1199 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1200 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1201 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1202 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1203 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1204 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1205 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1206 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1207 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1208 | struct nfs4_opendata *p; |
| 1209 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1210 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1211 | if (p == NULL) |
| 1212 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1213 | |
| 1214 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1215 | if (IS_ERR(p->f_label)) |
| 1216 | goto err_free_p; |
| 1217 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1218 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1219 | if (IS_ERR(p->a_label)) |
| 1220 | goto err_free_f; |
| 1221 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1222 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1223 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1224 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1225 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1226 | nfs_sb_active(dentry->d_sb); |
| 1227 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1228 | p->dir = parent; |
| 1229 | p->owner = sp; |
| 1230 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1231 | p->o_arg.open_flags = flags; |
| 1232 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1233 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1234 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1235 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1236 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1237 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1238 | * will return permission denied for all bits until close */ |
| 1239 | if (!(flags & O_EXCL)) { |
| 1240 | /* ask server to check for all possible rights as results |
| 1241 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1242 | switch (p->o_arg.claim) { |
| 1243 | default: |
| 1244 | break; |
| 1245 | case NFS4_OPEN_CLAIM_NULL: |
| 1246 | case NFS4_OPEN_CLAIM_FH: |
| 1247 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1248 | NFS4_ACCESS_MODIFY | |
| 1249 | NFS4_ACCESS_EXTEND | |
| 1250 | NFS4_ACCESS_EXECUTE; |
| 1251 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1252 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1253 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1254 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1255 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1256 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1257 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1258 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1259 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1260 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1261 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1262 | case NFS4_OPEN_CLAIM_NULL: |
| 1263 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1264 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1265 | p->o_arg.fh = NFS_FH(dir); |
| 1266 | break; |
| 1267 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1268 | case NFS4_OPEN_CLAIM_FH: |
| 1269 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1270 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1271 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1272 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1273 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1274 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1275 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1276 | p->o_arg.u.attrs = &p->attrs; |
| 1277 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1278 | |
| 1279 | verf[0] = jiffies; |
| 1280 | verf[1] = current->pid; |
| 1281 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1282 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1283 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1284 | p->c_arg.fh = &p->o_res.fh; |
| 1285 | p->c_arg.stateid = &p->o_res.stateid; |
| 1286 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1287 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1288 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1289 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1290 | |
| 1291 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1292 | nfs4_label_free(p->a_label); |
| 1293 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1294 | nfs4_label_free(p->f_label); |
| 1295 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1296 | kfree(p); |
| 1297 | err: |
| 1298 | dput(parent); |
| 1299 | return NULL; |
| 1300 | } |
| 1301 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1302 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1303 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1304 | struct nfs4_opendata *p = container_of(kref, |
| 1305 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1306 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1307 | |
| 1308 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1309 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1310 | if (p->state != NULL) |
| 1311 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1312 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1313 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1314 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1315 | nfs4_label_free(p->f_label); |
| 1316 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1317 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1318 | dput(p->dentry); |
| 1319 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1320 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1321 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1322 | kfree(p); |
| 1323 | } |
| 1324 | |
| 1325 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1326 | { |
| 1327 | if (p != NULL) |
| 1328 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1331 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1332 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1333 | int ret; |
| 1334 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1335 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1336 | return ret; |
| 1337 | } |
| 1338 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1339 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1340 | fmode_t fmode) |
| 1341 | { |
| 1342 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1343 | case FMODE_READ|FMODE_WRITE: |
| 1344 | return state->n_rdwr != 0; |
| 1345 | case FMODE_WRITE: |
| 1346 | return state->n_wronly != 0; |
| 1347 | case FMODE_READ: |
| 1348 | return state->n_rdonly != 0; |
| 1349 | } |
| 1350 | WARN_ON_ONCE(1); |
| 1351 | return false; |
| 1352 | } |
| 1353 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1354 | 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] | 1355 | { |
| 1356 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1358 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1359 | goto out; |
| 1360 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1361 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1362 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1363 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1364 | break; |
| 1365 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1366 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1367 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1368 | break; |
| 1369 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1370 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1371 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1372 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1373 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1374 | return ret; |
| 1375 | } |
| 1376 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1377 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1378 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1379 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1380 | if (delegation == NULL) |
| 1381 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1382 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1383 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1384 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1385 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1386 | switch (claim) { |
| 1387 | case NFS4_OPEN_CLAIM_NULL: |
| 1388 | case NFS4_OPEN_CLAIM_FH: |
| 1389 | break; |
| 1390 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1391 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1392 | break; |
| 1393 | default: |
| 1394 | return 0; |
| 1395 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1396 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1397 | return 1; |
| 1398 | } |
| 1399 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1400 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1401 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1402 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1403 | case FMODE_WRITE: |
| 1404 | state->n_wronly++; |
| 1405 | break; |
| 1406 | case FMODE_READ: |
| 1407 | state->n_rdonly++; |
| 1408 | break; |
| 1409 | case FMODE_READ|FMODE_WRITE: |
| 1410 | state->n_rdwr++; |
| 1411 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1412 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1415 | #ifdef CONFIG_NFS_V4_1 |
| 1416 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1417 | { |
| 1418 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1419 | return true; |
| 1420 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1421 | return true; |
| 1422 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1423 | return true; |
| 1424 | return false; |
| 1425 | } |
| 1426 | #endif /* CONFIG_NFS_V4_1 */ |
| 1427 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1428 | 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] | 1429 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1430 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1431 | bool need_recover = false; |
| 1432 | |
| 1433 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1434 | need_recover = true; |
| 1435 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1436 | need_recover = true; |
| 1437 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1438 | need_recover = true; |
| 1439 | if (need_recover) |
| 1440 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1441 | } |
| 1442 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1443 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1444 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1445 | { |
| 1446 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1447 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1448 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1449 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1450 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1451 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1452 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1453 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1454 | return true; |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1458 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1459 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1460 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1461 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1462 | if (state->n_wronly) |
| 1463 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1464 | if (state->n_rdonly) |
| 1465 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1466 | if (state->n_rdwr) |
| 1467 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1468 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1469 | } |
| 1470 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1471 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1472 | nfs4_stateid *stateid, fmode_t fmode) |
| 1473 | { |
| 1474 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1475 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1476 | case FMODE_WRITE: |
| 1477 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1478 | break; |
| 1479 | case FMODE_READ: |
| 1480 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1481 | break; |
| 1482 | case 0: |
| 1483 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1484 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1485 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1486 | } |
| 1487 | if (stateid == NULL) |
| 1488 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1489 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1490 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1491 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1492 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1493 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1494 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1495 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1496 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1497 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1498 | } |
| 1499 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1500 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1501 | nfs4_stateid *arg_stateid, |
| 1502 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1503 | { |
| 1504 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1505 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1506 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1507 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1508 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1510 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1513 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1514 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1515 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1516 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1517 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1518 | case FMODE_READ: |
| 1519 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1520 | break; |
| 1521 | case FMODE_WRITE: |
| 1522 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1523 | break; |
| 1524 | case FMODE_READ|FMODE_WRITE: |
| 1525 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1526 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1527 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1528 | return; |
| 1529 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1530 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1531 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1532 | } |
| 1533 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1534 | static void __update_open_stateid(struct nfs4_state *state, |
| 1535 | const nfs4_stateid *open_stateid, |
| 1536 | const nfs4_stateid *deleg_stateid, |
| 1537 | fmode_t fmode, |
| 1538 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1540 | /* |
| 1541 | * Protect the call to nfs4_state_set_mode_locked and |
| 1542 | * serialise the stateid update |
| 1543 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1544 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1545 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1546 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1547 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1548 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1549 | } |
| 1550 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1551 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1552 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1553 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1554 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1557 | static int update_open_stateid(struct nfs4_state *state, |
| 1558 | const nfs4_stateid *open_stateid, |
| 1559 | const nfs4_stateid *delegation, |
| 1560 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1561 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1562 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1563 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1564 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1565 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1566 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1567 | int ret = 0; |
| 1568 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1569 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1570 | |
| 1571 | rcu_read_lock(); |
| 1572 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1573 | if (deleg_cur == NULL) |
| 1574 | goto no_delegation; |
| 1575 | |
| 1576 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1577 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1578 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1579 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1580 | goto no_delegation_unlock; |
| 1581 | |
| 1582 | if (delegation == NULL) |
| 1583 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1584 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1585 | goto no_delegation_unlock; |
| 1586 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1587 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1588 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1589 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1590 | ret = 1; |
| 1591 | no_delegation_unlock: |
| 1592 | spin_unlock(&deleg_cur->lock); |
| 1593 | no_delegation: |
| 1594 | rcu_read_unlock(); |
| 1595 | |
| 1596 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1597 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1598 | ret = 1; |
| 1599 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1600 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1601 | nfs4_schedule_state_manager(clp); |
| 1602 | if (freeme.type != 0) |
| 1603 | nfs4_test_and_free_stateid(server, &freeme, |
| 1604 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1605 | |
| 1606 | return ret; |
| 1607 | } |
| 1608 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1609 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1610 | const nfs4_stateid *stateid) |
| 1611 | { |
| 1612 | struct nfs4_state *state = lsp->ls_state; |
| 1613 | bool ret = false; |
| 1614 | |
| 1615 | spin_lock(&state->state_lock); |
| 1616 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1617 | goto out_noupdate; |
| 1618 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1619 | goto out_noupdate; |
| 1620 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1621 | ret = true; |
| 1622 | out_noupdate: |
| 1623 | spin_unlock(&state->state_lock); |
| 1624 | return ret; |
| 1625 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1626 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1627 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1628 | { |
| 1629 | struct nfs_delegation *delegation; |
| 1630 | |
| 1631 | rcu_read_lock(); |
| 1632 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1633 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1634 | rcu_read_unlock(); |
| 1635 | return; |
| 1636 | } |
| 1637 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1638 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1639 | } |
| 1640 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1641 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1642 | { |
| 1643 | struct nfs4_state *state = opendata->state; |
| 1644 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1645 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1646 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1647 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1648 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1649 | nfs4_stateid stateid; |
| 1650 | int ret = -EAGAIN; |
| 1651 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1652 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1653 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1654 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1655 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1656 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1657 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1658 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1659 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1660 | rcu_read_lock(); |
| 1661 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1662 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1663 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1664 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1665 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1666 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1667 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1668 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1669 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1670 | if (!opendata->is_recover) { |
| 1671 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1672 | if (ret != 0) |
| 1673 | goto out; |
| 1674 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1675 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1676 | |
| 1677 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1678 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1679 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1680 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | out: |
| 1682 | return ERR_PTR(ret); |
| 1683 | out_return_state: |
| 1684 | atomic_inc(&state->count); |
| 1685 | return state; |
| 1686 | } |
| 1687 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1688 | static void |
| 1689 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1690 | { |
| 1691 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1692 | struct nfs_delegation *delegation; |
| 1693 | int delegation_flags = 0; |
| 1694 | |
| 1695 | rcu_read_lock(); |
| 1696 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1697 | if (delegation) |
| 1698 | delegation_flags = delegation->flags; |
| 1699 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1700 | switch (data->o_arg.claim) { |
| 1701 | default: |
| 1702 | break; |
| 1703 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1704 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1705 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1706 | "returning a delegation for " |
| 1707 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1708 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1709 | return; |
| 1710 | } |
| 1711 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1712 | nfs_inode_set_delegation(state->inode, |
| 1713 | data->owner->so_cred, |
| 1714 | &data->o_res); |
| 1715 | else |
| 1716 | nfs_inode_reclaim_delegation(state->inode, |
| 1717 | data->owner->so_cred, |
| 1718 | &data->o_res); |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1723 | * and update the nfs4_state. |
| 1724 | */ |
| 1725 | static struct nfs4_state * |
| 1726 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1727 | { |
| 1728 | struct inode *inode = data->state->inode; |
| 1729 | struct nfs4_state *state = data->state; |
| 1730 | int ret; |
| 1731 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1732 | if (!data->rpc_done) { |
| 1733 | if (data->rpc_status) { |
| 1734 | ret = data->rpc_status; |
| 1735 | goto err; |
| 1736 | } |
| 1737 | /* cached opens have already been processed */ |
| 1738 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1741 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1742 | if (ret) |
| 1743 | goto err; |
| 1744 | |
| 1745 | if (data->o_res.delegation_type != 0) |
| 1746 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1747 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1748 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1749 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1750 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1751 | |
| 1752 | return state; |
| 1753 | err: |
| 1754 | return ERR_PTR(ret); |
| 1755 | |
| 1756 | } |
| 1757 | |
| 1758 | static struct nfs4_state * |
| 1759 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1760 | { |
| 1761 | struct inode *inode; |
| 1762 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1763 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1764 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1765 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1766 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1767 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1768 | goto out; |
| 1769 | } |
| 1770 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1771 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1772 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1773 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1774 | 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] | 1775 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1776 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1777 | goto err; |
| 1778 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1779 | state = nfs4_get_open_state(inode, data->owner); |
| 1780 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1781 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1782 | if (data->o_res.delegation_type != 0) |
| 1783 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1784 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1785 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1786 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1787 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1788 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1789 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1790 | err_put_inode: |
| 1791 | iput(inode); |
| 1792 | err: |
| 1793 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1794 | } |
| 1795 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1796 | static struct nfs4_state * |
| 1797 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1798 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1799 | struct nfs4_state *ret; |
| 1800 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1801 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1802 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1803 | else |
| 1804 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1805 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1806 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1807 | } |
| 1808 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1809 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1810 | { |
| 1811 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1812 | struct nfs_open_context *ctx; |
| 1813 | |
| 1814 | spin_lock(&state->inode->i_lock); |
| 1815 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1816 | if (ctx->state != state) |
| 1817 | continue; |
| 1818 | get_nfs_open_context(ctx); |
| 1819 | spin_unlock(&state->inode->i_lock); |
| 1820 | return ctx; |
| 1821 | } |
| 1822 | spin_unlock(&state->inode->i_lock); |
| 1823 | return ERR_PTR(-ENOENT); |
| 1824 | } |
| 1825 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1826 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1827 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1828 | { |
| 1829 | struct nfs4_opendata *opendata; |
| 1830 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1831 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1832 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1833 | if (opendata == NULL) |
| 1834 | return ERR_PTR(-ENOMEM); |
| 1835 | opendata->state = state; |
| 1836 | atomic_inc(&state->count); |
| 1837 | return opendata; |
| 1838 | } |
| 1839 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1840 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1841 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1842 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1843 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1844 | int ret; |
| 1845 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1846 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1847 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1848 | opendata->o_arg.open_flags = 0; |
| 1849 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1850 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1851 | NFS_SB(opendata->dentry->d_sb), |
| 1852 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1853 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1854 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1855 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1856 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1857 | if (ret != 0) |
| 1858 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1859 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1860 | if (IS_ERR(newstate)) |
| 1861 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1862 | if (newstate != opendata->state) |
| 1863 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1864 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1865 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1869 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1870 | int ret; |
| 1871 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1872 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1873 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1874 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1875 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1876 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1877 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1878 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1879 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1880 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1881 | if (ret != 0) |
| 1882 | return ret; |
| 1883 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1884 | if (ret != 0) |
| 1885 | return ret; |
| 1886 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1887 | if (ret != 0) |
| 1888 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1889 | /* |
| 1890 | * We may have performed cached opens for all three recoveries. |
| 1891 | * Check if we need to update the current stateid. |
| 1892 | */ |
| 1893 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1894 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1895 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1896 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1897 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1898 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1899 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1900 | return 0; |
| 1901 | } |
| 1902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | /* |
| 1904 | * OPEN_RECLAIM: |
| 1905 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1907 | 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] | 1908 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1909 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1910 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1911 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | int status; |
| 1913 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1914 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1915 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1916 | if (IS_ERR(opendata)) |
| 1917 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1918 | rcu_read_lock(); |
| 1919 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1920 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1921 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1922 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1923 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1924 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1925 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | return status; |
| 1927 | } |
| 1928 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1929 | 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] | 1930 | { |
| 1931 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1932 | struct nfs4_exception exception = { }; |
| 1933 | int err; |
| 1934 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1935 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1936 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1937 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1938 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1939 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1940 | break; |
| 1941 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } while (exception.retry); |
| 1943 | return err; |
| 1944 | } |
| 1945 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1946 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1947 | { |
| 1948 | struct nfs_open_context *ctx; |
| 1949 | int ret; |
| 1950 | |
| 1951 | ctx = nfs4_state_find_open_context(state); |
| 1952 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1953 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1954 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1955 | put_nfs_open_context(ctx); |
| 1956 | return ret; |
| 1957 | } |
| 1958 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1959 | 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] | 1960 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1961 | switch (err) { |
| 1962 | default: |
| 1963 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1964 | "%d.\n", __func__, err); |
| 1965 | case 0: |
| 1966 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1967 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1968 | case -ESTALE: |
| 1969 | break; |
| 1970 | case -NFS4ERR_BADSESSION: |
| 1971 | case -NFS4ERR_BADSLOT: |
| 1972 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1973 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1974 | case -NFS4ERR_DEADSESSION: |
| 1975 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1976 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1977 | return -EAGAIN; |
| 1978 | case -NFS4ERR_STALE_CLIENTID: |
| 1979 | case -NFS4ERR_STALE_STATEID: |
| 1980 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1981 | /* Don't recall a delegation if it was lost */ |
| 1982 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1983 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1984 | case -NFS4ERR_MOVED: |
| 1985 | nfs4_schedule_migration_recovery(server); |
| 1986 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1987 | case -NFS4ERR_LEASE_MOVED: |
| 1988 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1989 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1990 | case -NFS4ERR_DELEG_REVOKED: |
| 1991 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1992 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1993 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1994 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1995 | nfs_inode_find_state_and_recover(state->inode, |
| 1996 | stateid); |
| 1997 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1998 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1999 | case -NFS4ERR_DELAY: |
| 2000 | case -NFS4ERR_GRACE: |
| 2001 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2002 | ssleep(1); |
| 2003 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2004 | case -ENOMEM: |
| 2005 | case -NFS4ERR_DENIED: |
| 2006 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 2007 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | return err; |
| 2010 | } |
| 2011 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2012 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2013 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2014 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2015 | { |
| 2016 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2017 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2018 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2019 | |
| 2020 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2021 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2022 | if (IS_ERR(opendata)) |
| 2023 | return PTR_ERR(opendata); |
| 2024 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2025 | write_seqlock(&state->seqlock); |
| 2026 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2027 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2028 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2029 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2030 | case FMODE_READ|FMODE_WRITE: |
| 2031 | case FMODE_WRITE: |
| 2032 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2033 | if (err) |
| 2034 | break; |
| 2035 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2036 | if (err) |
| 2037 | break; |
| 2038 | case FMODE_READ: |
| 2039 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2040 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2041 | nfs4_opendata_put(opendata); |
| 2042 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2043 | } |
| 2044 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2045 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2046 | { |
| 2047 | struct nfs4_opendata *data = calldata; |
| 2048 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2049 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2050 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2053 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2054 | { |
| 2055 | struct nfs4_opendata *data = calldata; |
| 2056 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2057 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2058 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2059 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2060 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2061 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2062 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2063 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2064 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2065 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | static void nfs4_open_confirm_release(void *calldata) |
| 2069 | { |
| 2070 | struct nfs4_opendata *data = calldata; |
| 2071 | struct nfs4_state *state = NULL; |
| 2072 | |
| 2073 | /* If this request hasn't been cancelled, do nothing */ |
| 2074 | if (data->cancelled == 0) |
| 2075 | goto out_free; |
| 2076 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2077 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2078 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2079 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2080 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2081 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2082 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2083 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2087 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2088 | .rpc_call_done = nfs4_open_confirm_done, |
| 2089 | .rpc_release = nfs4_open_confirm_release, |
| 2090 | }; |
| 2091 | |
| 2092 | /* |
| 2093 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2094 | */ |
| 2095 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2096 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2097 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2098 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2099 | struct rpc_message msg = { |
| 2100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2101 | .rpc_argp = &data->c_arg, |
| 2102 | .rpc_resp = &data->c_res, |
| 2103 | .rpc_cred = data->owner->so_cred, |
| 2104 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2105 | struct rpc_task_setup task_setup_data = { |
| 2106 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2107 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2108 | .callback_ops = &nfs4_open_confirm_ops, |
| 2109 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2110 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2111 | .flags = RPC_TASK_ASYNC, |
| 2112 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | int status; |
| 2114 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2115 | 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] | 2116 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2117 | data->rpc_done = 0; |
| 2118 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2119 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2120 | if (data->is_recover) |
| 2121 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2122 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2123 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2124 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2125 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2126 | if (status != 0) { |
| 2127 | data->cancelled = 1; |
| 2128 | smp_wmb(); |
| 2129 | } else |
| 2130 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2131 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | return status; |
| 2133 | } |
| 2134 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2135 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2137 | struct nfs4_opendata *data = calldata; |
| 2138 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2139 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2140 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2141 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2142 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2143 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2144 | /* |
| 2145 | * Check if we still need to send an OPEN call, or if we can use |
| 2146 | * a delegation instead. |
| 2147 | */ |
| 2148 | if (data->state != NULL) { |
| 2149 | struct nfs_delegation *delegation; |
| 2150 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2151 | 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] | 2152 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2153 | rcu_read_lock(); |
| 2154 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2155 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2156 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2157 | rcu_read_unlock(); |
| 2158 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2159 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2160 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2161 | switch (claim) { |
| 2162 | default: |
| 2163 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2164 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2165 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2166 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2167 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2168 | case NFS4_OPEN_CLAIM_FH: |
| 2169 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2170 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2171 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2172 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2173 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2174 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2175 | &data->o_res.seq_res, |
| 2176 | task) != 0) |
| 2177 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2178 | |
| 2179 | /* Set the create mode (note dependency on the session type) */ |
| 2180 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2181 | if (data->o_arg.open_flags & O_EXCL) { |
| 2182 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2183 | if (nfs4_has_persistent_session(clp)) |
| 2184 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2185 | else if (clp->cl_mvops->minor_version > 0) |
| 2186 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2187 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2188 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2189 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2190 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2191 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2192 | out_no_action: |
| 2193 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2194 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2195 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2196 | } |
| 2197 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2198 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2199 | { |
| 2200 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2202 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2203 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2204 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2205 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2206 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2207 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2208 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2209 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2210 | case S_IFREG: |
| 2211 | break; |
| 2212 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2213 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2214 | break; |
| 2215 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2216 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2217 | break; |
| 2218 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2219 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2220 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2221 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2222 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2223 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2224 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2225 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2226 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2227 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2228 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2229 | static void nfs4_open_release(void *calldata) |
| 2230 | { |
| 2231 | struct nfs4_opendata *data = calldata; |
| 2232 | struct nfs4_state *state = NULL; |
| 2233 | |
| 2234 | /* If this request hasn't been cancelled, do nothing */ |
| 2235 | if (data->cancelled == 0) |
| 2236 | goto out_free; |
| 2237 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2238 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2239 | goto out_free; |
| 2240 | /* In case we need an open_confirm, no cleanup! */ |
| 2241 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2242 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2243 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2244 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2245 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2246 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2247 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2251 | .rpc_call_prepare = nfs4_open_prepare, |
| 2252 | .rpc_call_done = nfs4_open_done, |
| 2253 | .rpc_release = nfs4_open_release, |
| 2254 | }; |
| 2255 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2256 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2257 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2258 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2259 | struct nfs_server *server = NFS_SERVER(dir); |
| 2260 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2261 | struct nfs_openres *o_res = &data->o_res; |
| 2262 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2263 | struct rpc_message msg = { |
| 2264 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2265 | .rpc_argp = o_arg, |
| 2266 | .rpc_resp = o_res, |
| 2267 | .rpc_cred = data->owner->so_cred, |
| 2268 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2269 | struct rpc_task_setup task_setup_data = { |
| 2270 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2271 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2272 | .callback_ops = &nfs4_open_ops, |
| 2273 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2274 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2275 | .flags = RPC_TASK_ASYNC, |
| 2276 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2277 | int status; |
| 2278 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2279 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2280 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2281 | data->rpc_done = 0; |
| 2282 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2283 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2284 | data->is_recover = 0; |
| 2285 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2286 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2287 | data->is_recover = 1; |
| 2288 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2289 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2290 | if (IS_ERR(task)) |
| 2291 | return PTR_ERR(task); |
| 2292 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2293 | if (status != 0) { |
| 2294 | data->cancelled = 1; |
| 2295 | smp_wmb(); |
| 2296 | } else |
| 2297 | status = data->rpc_status; |
| 2298 | rpc_put_task(task); |
| 2299 | |
| 2300 | return status; |
| 2301 | } |
| 2302 | |
| 2303 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2304 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2305 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2306 | struct nfs_openres *o_res = &data->o_res; |
| 2307 | int status; |
| 2308 | |
| 2309 | status = nfs4_run_open_task(data, 1); |
| 2310 | if (status != 0 || !data->rpc_done) |
| 2311 | return status; |
| 2312 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2313 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2314 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2315 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2316 | status = _nfs4_proc_open_confirm(data); |
| 2317 | if (status != 0) |
| 2318 | return status; |
| 2319 | } |
| 2320 | |
| 2321 | return status; |
| 2322 | } |
| 2323 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2324 | /* |
| 2325 | * Additional permission checks in order to distinguish between an |
| 2326 | * open for read, and an open for execute. This works around the |
| 2327 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2328 | * the same. |
| 2329 | * Note that in the non-execute case, we want to turn off permission |
| 2330 | * checking if we just created a new file (POSIX open() semantics). |
| 2331 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2332 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2333 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2334 | struct nfs4_state *state, fmode_t fmode, |
| 2335 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2336 | { |
| 2337 | struct nfs_access_entry cache; |
| 2338 | u32 mask; |
| 2339 | |
| 2340 | /* access call failed or for some reason the server doesn't |
| 2341 | * support any access modes -- defer access call until later */ |
| 2342 | if (opendata->o_res.access_supported == 0) |
| 2343 | return 0; |
| 2344 | |
| 2345 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2346 | /* |
| 2347 | * Use openflags to check for exec, because fmode won't |
| 2348 | * always have FMODE_EXEC set when file open for exec. |
| 2349 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2350 | if (openflags & __FMODE_EXEC) { |
| 2351 | /* ONLY check for exec rights */ |
| 2352 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2353 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2354 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2355 | |
| 2356 | cache.cred = cred; |
| 2357 | cache.jiffies = jiffies; |
| 2358 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2359 | nfs_access_add_cache(state->inode, &cache); |
| 2360 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2361 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2362 | return 0; |
| 2363 | |
| 2364 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2365 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2366 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2367 | } |
| 2368 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2369 | /* |
| 2370 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2371 | */ |
| 2372 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2373 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2374 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2375 | struct nfs_server *server = NFS_SERVER(dir); |
| 2376 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2377 | struct nfs_openres *o_res = &data->o_res; |
| 2378 | int status; |
| 2379 | |
| 2380 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2381 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2382 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2383 | if (status != 0) { |
| 2384 | if (status == -NFS4ERR_BADNAME && |
| 2385 | !(o_arg->open_flags & O_CREAT)) |
| 2386 | return -ENOENT; |
| 2387 | return status; |
| 2388 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2389 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2390 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2391 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2392 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2393 | if (o_arg->open_flags & O_EXCL) |
| 2394 | data->file_created = 1; |
| 2395 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2396 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2397 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
| 2398 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2399 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2400 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2401 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2403 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2405 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
| 2407 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2408 | 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] | 2409 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2412 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2413 | { |
| 2414 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2415 | } |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | /* |
| 2418 | * OPEN_EXPIRED: |
| 2419 | * reclaim state on the server after a network partition. |
| 2420 | * Assumes caller holds the appropriate lock |
| 2421 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2422 | 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] | 2423 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2424 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2425 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2427 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2428 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2429 | if (IS_ERR(opendata)) |
| 2430 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2431 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2432 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2433 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2434 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2435 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2438 | 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] | 2439 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2440 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2441 | struct nfs4_exception exception = { }; |
| 2442 | int err; |
| 2443 | |
| 2444 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2445 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2446 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2447 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2448 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2449 | switch (err) { |
| 2450 | default: |
| 2451 | goto out; |
| 2452 | case -NFS4ERR_GRACE: |
| 2453 | case -NFS4ERR_DELAY: |
| 2454 | nfs4_handle_exception(server, err, &exception); |
| 2455 | err = 0; |
| 2456 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2457 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2458 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2459 | return err; |
| 2460 | } |
| 2461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2463 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2465 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2467 | ctx = nfs4_state_find_open_context(state); |
| 2468 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2469 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2470 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2471 | put_nfs_open_context(ctx); |
| 2472 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2475 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2476 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2477 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2478 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2479 | write_seqlock(&state->seqlock); |
| 2480 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2481 | write_sequnlock(&state->seqlock); |
| 2482 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2483 | } |
| 2484 | |
| 2485 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2486 | { |
| 2487 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2488 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2492 | { |
| 2493 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2494 | nfs40_clear_delegation_stateid(state); |
| 2495 | return nfs4_open_expired(sp, state); |
| 2496 | } |
| 2497 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2498 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2499 | nfs4_stateid *stateid, |
| 2500 | struct rpc_cred *cred) |
| 2501 | { |
| 2502 | return -NFS4ERR_BAD_STATEID; |
| 2503 | } |
| 2504 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2505 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2506 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2507 | nfs4_stateid *stateid, |
| 2508 | struct rpc_cred *cred) |
| 2509 | { |
| 2510 | int status; |
| 2511 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2512 | switch (stateid->type) { |
| 2513 | default: |
| 2514 | break; |
| 2515 | case NFS4_INVALID_STATEID_TYPE: |
| 2516 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2517 | return -NFS4ERR_BAD_STATEID; |
| 2518 | case NFS4_REVOKED_STATEID_TYPE: |
| 2519 | goto out_free; |
| 2520 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2521 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2522 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2523 | switch (status) { |
| 2524 | case -NFS4ERR_EXPIRED: |
| 2525 | case -NFS4ERR_ADMIN_REVOKED: |
| 2526 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2527 | break; |
| 2528 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2529 | return status; |
| 2530 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2531 | out_free: |
| 2532 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2533 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2534 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2537 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2538 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2539 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2540 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2541 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2542 | struct rpc_cred *cred; |
| 2543 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2544 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2545 | /* Get the delegation credential for use by test/free_stateid */ |
| 2546 | rcu_read_lock(); |
| 2547 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2548 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2549 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2550 | return; |
| 2551 | } |
| 2552 | |
| 2553 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2554 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2555 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2556 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2557 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2558 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2559 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2560 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2561 | rcu_read_unlock(); |
| 2562 | return; |
| 2563 | } |
| 2564 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2565 | cred = get_rpccred(delegation->cred); |
| 2566 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2567 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2568 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2569 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2570 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2571 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2572 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2576 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2577 | * |
| 2578 | * @state: NFSv4 state for an inode |
| 2579 | * |
| 2580 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2581 | * Otherwise a negative NFS4ERR value is returned. |
| 2582 | */ |
| 2583 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2584 | { |
| 2585 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2586 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2587 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2588 | |
| 2589 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2590 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2591 | |
| 2592 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2593 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2594 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2595 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2596 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2597 | atomic_inc(&lsp->ls_count); |
| 2598 | spin_unlock(&state->state_lock); |
| 2599 | |
| 2600 | nfs4_put_lock_state(prev); |
| 2601 | prev = lsp; |
| 2602 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2603 | status = nfs41_test_and_free_expired_stateid(server, |
| 2604 | &lsp->ls_stateid, |
| 2605 | cred); |
| 2606 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2607 | if (status == -NFS4ERR_EXPIRED || |
| 2608 | status == -NFS4ERR_BAD_STATEID) { |
| 2609 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2610 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2611 | if (!recover_lost_locks) |
| 2612 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2613 | } else if (status != NFS_OK) { |
| 2614 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2615 | nfs4_put_lock_state(prev); |
| 2616 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2617 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2618 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2619 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2620 | } |
| 2621 | spin_unlock(&state->state_lock); |
| 2622 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2623 | out: |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
| 2627 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2629 | * |
| 2630 | * @state: NFSv4 state for an inode |
| 2631 | * |
| 2632 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2633 | * Otherwise a negative NFS4ERR value is returned. |
| 2634 | */ |
| 2635 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2636 | { |
| 2637 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2638 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2639 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2640 | int status; |
| 2641 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2642 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2643 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2644 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2645 | return NFS_OK; |
| 2646 | return -NFS4ERR_OPENMODE; |
| 2647 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2648 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2649 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2650 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2651 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2652 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2653 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2654 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2655 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2656 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2657 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2658 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2659 | if (status != NFS_OK) |
| 2660 | return status; |
| 2661 | if (nfs_open_stateid_recover_openmode(state)) |
| 2662 | return -NFS4ERR_OPENMODE; |
| 2663 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2667 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2668 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2669 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2670 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2671 | status = nfs41_check_expired_locks(state); |
| 2672 | if (status != NFS_OK) |
| 2673 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2674 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2675 | if (status != NFS_OK) |
| 2676 | status = nfs4_open_expired(sp, state); |
| 2677 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2678 | } |
| 2679 | #endif |
| 2680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2682 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2683 | * fields corresponding to attributes that were used to store the verifier. |
| 2684 | * Make sure we clobber those fields in the later setattr call |
| 2685 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2686 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2687 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2688 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2689 | const u32 *attrset = opendata->o_res.attrset; |
| 2690 | |
| 2691 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2692 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2693 | sattr->ia_valid |= ATTR_ATIME; |
| 2694 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2695 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2696 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2697 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2698 | |
| 2699 | /* Except MODE, it seems harmless of setting twice. */ |
| 2700 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2701 | sattr->ia_valid &= ~ATTR_MODE; |
| 2702 | |
| 2703 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2704 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2705 | } |
| 2706 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2707 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2708 | fmode_t fmode, |
| 2709 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2710 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2711 | { |
| 2712 | struct nfs4_state_owner *sp = opendata->owner; |
| 2713 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2714 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2715 | struct nfs4_state *state; |
| 2716 | unsigned int seq; |
| 2717 | int ret; |
| 2718 | |
| 2719 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2720 | |
| 2721 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2722 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2723 | goto out; |
| 2724 | |
| 2725 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2726 | ret = PTR_ERR(state); |
| 2727 | if (IS_ERR(state)) |
| 2728 | goto out; |
| 2729 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2730 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2731 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2732 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2733 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2734 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2735 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2736 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2737 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2738 | alias = d_exact_alias(dentry, state->inode); |
| 2739 | if (!alias) |
| 2740 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2741 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2742 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2743 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2744 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2745 | } |
| 2746 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2747 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2748 | } |
| 2749 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2750 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2751 | if (ret != 0) |
| 2752 | goto out; |
| 2753 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2754 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2755 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2756 | nfs_inode_attach_open_context(ctx); |
| 2757 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2758 | nfs4_schedule_stateid_recovery(server, state); |
| 2759 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2760 | out: |
| 2761 | return ret; |
| 2762 | } |
| 2763 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2764 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2765 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2767 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2768 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2769 | int flags, |
| 2770 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2771 | struct nfs4_label *label, |
| 2772 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | { |
| 2774 | struct nfs4_state_owner *sp; |
| 2775 | struct nfs4_state *state = NULL; |
| 2776 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2777 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2778 | struct dentry *dentry = ctx->dentry; |
| 2779 | struct rpc_cred *cred = ctx->cred; |
| 2780 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2781 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2782 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2783 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2784 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
| 2786 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2788 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2789 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2791 | goto out_err; |
| 2792 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2793 | status = nfs4_recover_expired_lease(server); |
| 2794 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2795 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2796 | if (d_really_is_positive(dentry)) |
| 2797 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2798 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2799 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2800 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2801 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2802 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2803 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2804 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2806 | if (label) { |
| 2807 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2808 | if (IS_ERR(olabel)) { |
| 2809 | status = PTR_ERR(olabel); |
| 2810 | goto err_opendata_put; |
| 2811 | } |
| 2812 | } |
| 2813 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2814 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2815 | if (!opendata->f_attr.mdsthreshold) { |
| 2816 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2817 | if (!opendata->f_attr.mdsthreshold) |
| 2818 | goto err_free_label; |
| 2819 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2820 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2821 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2822 | if (d_really_is_positive(dentry)) |
| 2823 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2824 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2825 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2826 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2827 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2828 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2829 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2830 | 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] | 2831 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2832 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2833 | /* |
| 2834 | * send create attributes which was not set by open |
| 2835 | * with an extra setattr. |
| 2836 | */ |
| 2837 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2838 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2839 | status = nfs4_do_setattr(state->inode, cred, |
| 2840 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2841 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2842 | if (status == 0) { |
| 2843 | nfs_setattr_update_inode(state->inode, sattr, |
| 2844 | opendata->o_res.f_attr); |
| 2845 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2846 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2847 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2848 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2849 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2850 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2851 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2852 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2853 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2854 | opendata->f_attr.mdsthreshold = NULL; |
| 2855 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2856 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2857 | nfs4_label_free(olabel); |
| 2858 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2859 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2862 | err_free_label: |
| 2863 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2864 | err_opendata_put: |
| 2865 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2866 | err_put_state_owner: |
| 2867 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | return status; |
| 2870 | } |
| 2871 | |
| 2872 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2873 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2874 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2875 | int flags, |
| 2876 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2877 | struct nfs4_label *label, |
| 2878 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2880 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | struct nfs4_exception exception = { }; |
| 2882 | struct nfs4_state *res; |
| 2883 | int status; |
| 2884 | |
| 2885 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2886 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2887 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2888 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | if (status == 0) |
| 2890 | break; |
| 2891 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2892 | * book-keeping w.r.t. state-changing operations |
| 2893 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2894 | * It is actually a sign of a bug on the client or on the server. |
| 2895 | * |
| 2896 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2897 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | * have unhashed the old state_owner for us, and that we can |
| 2899 | * therefore safely retry using a new one. We should still warn |
| 2900 | * the user though... |
| 2901 | */ |
| 2902 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2903 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2904 | " returned a bad sequence-id error!\n", |
| 2905 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | exception.retry = 1; |
| 2907 | continue; |
| 2908 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2909 | /* |
| 2910 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2911 | * state before it received the OPEN_CONFIRM. |
| 2912 | * Recover by retrying the request as per the discussion |
| 2913 | * on Page 181 of RFC3530. |
| 2914 | */ |
| 2915 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2916 | exception.retry = 1; |
| 2917 | continue; |
| 2918 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2919 | if (status == -EAGAIN) { |
| 2920 | /* We must have found a delegation */ |
| 2921 | exception.retry = 1; |
| 2922 | continue; |
| 2923 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2924 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2925 | continue; |
| 2926 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | status, &exception)); |
| 2928 | } while (exception.retry); |
| 2929 | return res; |
| 2930 | } |
| 2931 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2932 | static int _nfs4_do_setattr(struct inode *inode, |
| 2933 | struct nfs_setattrargs *arg, |
| 2934 | struct nfs_setattrres *res, |
| 2935 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2936 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2937 | { |
| 2938 | struct nfs_server *server = NFS_SERVER(inode); |
| 2939 | struct rpc_message msg = { |
| 2940 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2941 | .rpc_argp = arg, |
| 2942 | .rpc_resp = res, |
| 2943 | .rpc_cred = cred, |
| 2944 | }; |
| 2945 | struct rpc_cred *delegation_cred = NULL; |
| 2946 | unsigned long timestamp = jiffies; |
| 2947 | fmode_t fmode; |
| 2948 | bool truncate; |
| 2949 | int status; |
| 2950 | |
| 2951 | nfs_fattr_init(res->fattr); |
| 2952 | |
| 2953 | /* Servers should only apply open mode checks for file size changes */ |
| 2954 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2955 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2956 | |
| 2957 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2958 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2959 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2960 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2961 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2962 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2963 | l_ctx = nfs_get_lock_context(ctx); |
| 2964 | if (IS_ERR(l_ctx)) |
| 2965 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2966 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2967 | &arg->stateid, &delegation_cred); |
| 2968 | nfs_put_lock_context(l_ctx); |
| 2969 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2970 | return -EBADF; |
| 2971 | } else |
| 2972 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2973 | if (delegation_cred) |
| 2974 | msg.rpc_cred = delegation_cred; |
| 2975 | |
| 2976 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2977 | |
| 2978 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2979 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2980 | renew_lease(server, timestamp); |
| 2981 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2982 | return status; |
| 2983 | } |
| 2984 | |
| 2985 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2986 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2987 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2988 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2990 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2991 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2993 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | .iap = sattr, |
| 2995 | .server = server, |
| 2996 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2997 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | }; |
| 2999 | struct nfs_setattrres res = { |
| 3000 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3001 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | .server = server, |
| 3003 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3004 | struct nfs4_exception exception = { |
| 3005 | .state = state, |
| 3006 | .inode = inode, |
| 3007 | .stateid = &arg.stateid, |
| 3008 | }; |
| 3009 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3011 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3012 | if (ilabel) |
| 3013 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3016 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3017 | switch (err) { |
| 3018 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3019 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3020 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3021 | "applying open mode checks to " |
| 3022 | "a SETATTR that is not " |
| 3023 | "changing file size.\n", |
| 3024 | server->nfs_client->cl_hostname); |
| 3025 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3026 | if (state && !(state->state & FMODE_WRITE)) { |
| 3027 | err = -EBADF; |
| 3028 | if (sattr->ia_valid & ATTR_OPEN) |
| 3029 | err = -EACCES; |
| 3030 | goto out; |
| 3031 | } |
| 3032 | } |
| 3033 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3035 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | return err; |
| 3037 | } |
| 3038 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3039 | static bool |
| 3040 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3041 | { |
| 3042 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3043 | return false; |
| 3044 | |
| 3045 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3046 | } |
| 3047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | struct nfs4_closedata { |
| 3049 | struct inode *inode; |
| 3050 | struct nfs4_state *state; |
| 3051 | struct nfs_closeargs arg; |
| 3052 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3053 | struct { |
| 3054 | struct nfs4_layoutreturn_args arg; |
| 3055 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3056 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3057 | u32 roc_barrier; |
| 3058 | bool roc; |
| 3059 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3060 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3061 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | }; |
| 3063 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3064 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3065 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3066 | struct nfs4_closedata *calldata = data; |
| 3067 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3068 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3069 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3070 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3071 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3072 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3073 | nfs4_put_open_state(calldata->state); |
| 3074 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3075 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3076 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3077 | kfree(calldata); |
| 3078 | } |
| 3079 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3080 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3082 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3085 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3087 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3088 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3089 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3090 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3091 | |
| 3092 | /* Handle Layoutreturn errors */ |
| 3093 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3094 | switch (calldata->res.lr_ret) { |
| 3095 | default: |
| 3096 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3097 | break; |
| 3098 | case 0: |
| 3099 | calldata->arg.lr_args = NULL; |
| 3100 | calldata->res.lr_res = NULL; |
| 3101 | break; |
| 3102 | case -NFS4ERR_ADMIN_REVOKED: |
| 3103 | case -NFS4ERR_DELEG_REVOKED: |
| 3104 | case -NFS4ERR_EXPIRED: |
| 3105 | case -NFS4ERR_BAD_STATEID: |
| 3106 | case -NFS4ERR_OLD_STATEID: |
| 3107 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3108 | case -NFS4ERR_WRONG_CRED: |
| 3109 | calldata->arg.lr_args = NULL; |
| 3110 | calldata->res.lr_res = NULL; |
| 3111 | calldata->res.lr_ret = 0; |
| 3112 | rpc_restart_call_prepare(task); |
| 3113 | return; |
| 3114 | } |
| 3115 | } |
| 3116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | /* hmm. we are done with the inode, and in the process of freeing |
| 3118 | * the state_owner. we keep this around to process errors |
| 3119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | switch (task->tk_status) { |
| 3121 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3122 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3123 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3124 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3125 | case -NFS4ERR_ACCESS: |
| 3126 | if (calldata->arg.bitmask != NULL) { |
| 3127 | calldata->arg.bitmask = NULL; |
| 3128 | calldata->res.fattr = NULL; |
| 3129 | task->tk_status = 0; |
| 3130 | rpc_restart_call_prepare(task); |
| 3131 | goto out_release; |
| 3132 | |
| 3133 | } |
| 3134 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3135 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3137 | case -NFS4ERR_EXPIRED: |
| 3138 | nfs4_free_revoked_stateid(server, |
| 3139 | &calldata->arg.stateid, |
| 3140 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3141 | case -NFS4ERR_OLD_STATEID: |
| 3142 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3143 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3144 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3145 | rpc_restart_call_prepare(task); |
| 3146 | goto out_release; |
| 3147 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3148 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3149 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3151 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3152 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3153 | goto out_release; |
| 3154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3156 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3157 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3158 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3159 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3160 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3161 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3164 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3166 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3167 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3168 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3169 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3170 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3171 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3172 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3173 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3174 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3175 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3176 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3177 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3178 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3179 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3180 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3181 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3182 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3183 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3184 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3185 | if (state->n_rdonly == 0) |
| 3186 | call_close |= is_rdonly; |
| 3187 | else if (is_rdonly) |
| 3188 | calldata->arg.fmode |= FMODE_READ; |
| 3189 | if (state->n_wronly == 0) |
| 3190 | call_close |= is_wronly; |
| 3191 | else if (is_wronly) |
| 3192 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3193 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3194 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3195 | } else if (is_rdwr) |
| 3196 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3197 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3198 | if (!nfs4_valid_open_stateid(state) || |
| 3199 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3200 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3201 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3202 | |
| 3203 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3204 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3205 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3206 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3207 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3208 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3209 | nfs_release_seqid(calldata->arg.seqid); |
| 3210 | goto out_wait; |
| 3211 | } |
| 3212 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3213 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3214 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3215 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3216 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3217 | /* Close-to-open cache consistency revalidation */ |
| 3218 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3219 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3220 | else |
| 3221 | calldata->arg.bitmask = NULL; |
| 3222 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3223 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3224 | calldata->arg.share_access = |
| 3225 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3226 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3227 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3228 | if (calldata->res.fattr == NULL) |
| 3229 | calldata->arg.bitmask = NULL; |
| 3230 | else if (calldata->arg.bitmask == NULL) |
| 3231 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3232 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3233 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3234 | &calldata->arg.seq_args, |
| 3235 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3236 | task) != 0) |
| 3237 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3238 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3239 | return; |
| 3240 | out_no_action: |
| 3241 | task->tk_action = NULL; |
| 3242 | out_wait: |
| 3243 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3246 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3247 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3248 | .rpc_call_done = nfs4_close_done, |
| 3249 | .rpc_release = nfs4_free_closedata, |
| 3250 | }; |
| 3251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | /* |
| 3253 | * It is possible for data to be read/written from a mem-mapped file |
| 3254 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3255 | * This means that we can't safely call nfsv4 close on a file until |
| 3256 | * the inode is cleared. This in turn means that we are not good |
| 3257 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3258 | * share state even when we are done with one of the three share |
| 3259 | * stateid's in the inode. |
| 3260 | * |
| 3261 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3262 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3263 | 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] | 3264 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3265 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3266 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3268 | struct nfs4_state_owner *sp = state->owner; |
| 3269 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3270 | struct rpc_message msg = { |
| 3271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3272 | .rpc_cred = state->owner->so_cred, |
| 3273 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3274 | struct rpc_task_setup task_setup_data = { |
| 3275 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3276 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3277 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3278 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3279 | .flags = RPC_TASK_ASYNC, |
| 3280 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3281 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3283 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3284 | &task_setup_data.rpc_client, &msg); |
| 3285 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3286 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3288 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3289 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3290 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3292 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3294 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3295 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3296 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3297 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3298 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3299 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3300 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3301 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3302 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3303 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3304 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3305 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3306 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3307 | if (calldata->lr.roc) { |
| 3308 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3309 | calldata->res.lr_res = &calldata->lr.res; |
| 3310 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3311 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3312 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3313 | msg.rpc_argp = &calldata->arg; |
| 3314 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3315 | task_setup_data.callback_data = calldata; |
| 3316 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3317 | if (IS_ERR(task)) |
| 3318 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3319 | status = 0; |
| 3320 | if (wait) |
| 3321 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3322 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3323 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3324 | out_free_calldata: |
| 3325 | kfree(calldata); |
| 3326 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3327 | nfs4_put_open_state(state); |
| 3328 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3329 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3332 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3333 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3334 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3337 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3338 | |
| 3339 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3341 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3342 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3343 | |
| 3344 | nfs4_label_release_security(label); |
| 3345 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3346 | if (IS_ERR(state)) |
| 3347 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3348 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3351 | 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] | 3352 | { |
| 3353 | if (ctx->state == NULL) |
| 3354 | return; |
| 3355 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3356 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3357 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3358 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3361 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3362 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3363 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3366 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3367 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3368 | struct nfs4_server_caps_arg args = { |
| 3369 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3370 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3371 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | struct nfs4_server_caps_res res = {}; |
| 3373 | struct rpc_message msg = { |
| 3374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3375 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | .rpc_resp = &res, |
| 3377 | }; |
| 3378 | int status; |
| 3379 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3380 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3381 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3382 | FATTR4_WORD0_LINK_SUPPORT | |
| 3383 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3384 | FATTR4_WORD0_ACLSUPPORT; |
| 3385 | if (minorversion) |
| 3386 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3387 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3388 | 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] | 3389 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3390 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3391 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3392 | case 0: |
| 3393 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3394 | res.attr_bitmask[2] = 0; |
| 3395 | break; |
| 3396 | case 1: |
| 3397 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3398 | break; |
| 3399 | case 2: |
| 3400 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3403 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3404 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3405 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3406 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3407 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3408 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3409 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3410 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | server->caps |= NFS_CAP_ACLS; |
| 3412 | if (res.has_links != 0) |
| 3413 | server->caps |= NFS_CAP_HARDLINKS; |
| 3414 | if (res.has_symlinks != 0) |
| 3415 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3416 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3417 | server->caps |= NFS_CAP_FILEID; |
| 3418 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3419 | server->caps |= NFS_CAP_MODE; |
| 3420 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3421 | server->caps |= NFS_CAP_NLINK; |
| 3422 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3423 | server->caps |= NFS_CAP_OWNER; |
| 3424 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3425 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3426 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3427 | server->caps |= NFS_CAP_ATIME; |
| 3428 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3429 | server->caps |= NFS_CAP_CTIME; |
| 3430 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3431 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3432 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3433 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3434 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3435 | #endif |
| 3436 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3437 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3438 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3439 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3440 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3441 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3442 | 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] | 3443 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3444 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3445 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3447 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | return status; |
| 3451 | } |
| 3452 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3453 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | { |
| 3455 | struct nfs4_exception exception = { }; |
| 3456 | int err; |
| 3457 | do { |
| 3458 | err = nfs4_handle_exception(server, |
| 3459 | _nfs4_server_capabilities(server, fhandle), |
| 3460 | &exception); |
| 3461 | } while (exception.retry); |
| 3462 | return err; |
| 3463 | } |
| 3464 | |
| 3465 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3466 | struct nfs_fsinfo *info) |
| 3467 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3468 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3470 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | }; |
| 3472 | struct nfs4_lookup_res res = { |
| 3473 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3474 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | .fh = fhandle, |
| 3476 | }; |
| 3477 | struct rpc_message msg = { |
| 3478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3479 | .rpc_argp = &args, |
| 3480 | .rpc_resp = &res, |
| 3481 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3482 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3483 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3484 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3485 | /* |
| 3486 | * Process the label in the upcoming getfattr |
| 3487 | */ |
| 3488 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3489 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3490 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3491 | 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] | 3492 | } |
| 3493 | |
| 3494 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3495 | struct nfs_fsinfo *info) |
| 3496 | { |
| 3497 | struct nfs4_exception exception = { }; |
| 3498 | int err; |
| 3499 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3500 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3501 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3502 | switch (err) { |
| 3503 | case 0: |
| 3504 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3505 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3506 | default: |
| 3507 | err = nfs4_handle_exception(server, err, &exception); |
| 3508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3510 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | return err; |
| 3512 | } |
| 3513 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3514 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3515 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3516 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3517 | struct rpc_auth_create_args auth_args = { |
| 3518 | .pseudoflavor = flavor, |
| 3519 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3520 | struct rpc_auth *auth; |
| 3521 | int ret; |
| 3522 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3523 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3524 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3525 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3526 | goto out; |
| 3527 | } |
| 3528 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3529 | out: |
| 3530 | return ret; |
| 3531 | } |
| 3532 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3533 | /* |
| 3534 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3535 | * |
| 3536 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3537 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3538 | * |
| 3539 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3540 | * negative errno value. |
| 3541 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3542 | 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] | 3543 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3545 | /* Per 3530bis 15.33.5 */ |
| 3546 | static const rpc_authflavor_t flav_array[] = { |
| 3547 | RPC_AUTH_GSS_KRB5P, |
| 3548 | RPC_AUTH_GSS_KRB5I, |
| 3549 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3550 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3551 | RPC_AUTH_NULL, |
| 3552 | }; |
| 3553 | int status = -EPERM; |
| 3554 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3556 | if (server->auth_info.flavor_len > 0) { |
| 3557 | /* try each flavor specified by user */ |
| 3558 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3559 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3560 | server->auth_info.flavors[i]); |
| 3561 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3562 | continue; |
| 3563 | break; |
| 3564 | } |
| 3565 | } else { |
| 3566 | /* no flavors specified by user, try default list */ |
| 3567 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3568 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3569 | flav_array[i]); |
| 3570 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3571 | continue; |
| 3572 | break; |
| 3573 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3574 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3575 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3576 | /* |
| 3577 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3578 | * to access the mount. It could also mean that we tried to mount |
| 3579 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3580 | * existing mount programs don't handle -EACCES very well so it should |
| 3581 | * be mapped to -EPERM instead. |
| 3582 | */ |
| 3583 | if (status == -EACCES) |
| 3584 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3585 | return status; |
| 3586 | } |
| 3587 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3588 | /** |
| 3589 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3590 | * @server: initialized nfs_server handle |
| 3591 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3592 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3593 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3594 | * |
| 3595 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3596 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3597 | 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] | 3598 | struct nfs_fsinfo *info, |
| 3599 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3600 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3601 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3602 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3603 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3604 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3605 | |
| 3606 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3607 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3608 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | if (status == 0) |
| 3611 | status = nfs4_server_capabilities(server, fhandle); |
| 3612 | if (status == 0) |
| 3613 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3614 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3615 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3618 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3619 | struct nfs_fsinfo *info) |
| 3620 | { |
| 3621 | int error; |
| 3622 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3623 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3624 | |
| 3625 | error = nfs4_server_capabilities(server, mntfh); |
| 3626 | if (error < 0) { |
| 3627 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3628 | return error; |
| 3629 | } |
| 3630 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3631 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3632 | if (IS_ERR(label)) |
| 3633 | return PTR_ERR(label); |
| 3634 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3635 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3636 | if (error < 0) { |
| 3637 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3638 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3642 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3643 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3644 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3645 | err_free_label: |
| 3646 | nfs4_label_free(label); |
| 3647 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3648 | return error; |
| 3649 | } |
| 3650 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3651 | /* |
| 3652 | * Get locations and (maybe) other attributes of a referral. |
| 3653 | * Note that we'll actually follow the referral later when |
| 3654 | * we detect fsid mismatch in inode revalidation |
| 3655 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3656 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3657 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3658 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3659 | { |
| 3660 | int status = -ENOMEM; |
| 3661 | struct page *page = NULL; |
| 3662 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3663 | |
| 3664 | page = alloc_page(GFP_KERNEL); |
| 3665 | if (page == NULL) |
| 3666 | goto out; |
| 3667 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3668 | if (locations == NULL) |
| 3669 | goto out; |
| 3670 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3671 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3672 | if (status != 0) |
| 3673 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3674 | |
| 3675 | /* |
| 3676 | * If the fsid didn't change, this is a migration event, not a |
| 3677 | * referral. Cause us to drop into the exception handler, which |
| 3678 | * will kick off migration recovery. |
| 3679 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3680 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3681 | dprintk("%s: server did not return a different fsid for" |
| 3682 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3683 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3684 | goto out; |
| 3685 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3686 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3687 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3688 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3689 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3690 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3691 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3692 | out: |
| 3693 | if (page) |
| 3694 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3695 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3696 | return status; |
| 3697 | } |
| 3698 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3699 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3700 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | { |
| 3702 | struct nfs4_getattr_arg args = { |
| 3703 | .fh = fhandle, |
| 3704 | .bitmask = server->attr_bitmask, |
| 3705 | }; |
| 3706 | struct nfs4_getattr_res res = { |
| 3707 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3708 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | .server = server, |
| 3710 | }; |
| 3711 | struct rpc_message msg = { |
| 3712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3713 | .rpc_argp = &args, |
| 3714 | .rpc_resp = &res, |
| 3715 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3716 | |
| 3717 | args.bitmask = nfs4_bitmask(server, label); |
| 3718 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3719 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3720 | 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] | 3721 | } |
| 3722 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3723 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3724 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | { |
| 3726 | struct nfs4_exception exception = { }; |
| 3727 | int err; |
| 3728 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3729 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3730 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3731 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | &exception); |
| 3733 | } while (exception.retry); |
| 3734 | return err; |
| 3735 | } |
| 3736 | |
| 3737 | /* |
| 3738 | * The file is not closed if it is opened due to the a request to change |
| 3739 | * the size of the file. The open call will not be needed once the |
| 3740 | * VFS layer lookup-intents are implemented. |
| 3741 | * |
| 3742 | * Close is called when the inode is destroyed. |
| 3743 | * If we haven't opened the file for O_WRONLY, we |
| 3744 | * need to in the size_change case to obtain a stateid. |
| 3745 | * |
| 3746 | * Got race? |
| 3747 | * Because OPEN is always done by name in nfsv4, it is |
| 3748 | * possible that we opened a different file by the same |
| 3749 | * name. We can recognize this race condition, but we |
| 3750 | * can't do anything about it besides returning an error. |
| 3751 | * |
| 3752 | * This will be fixed with VFS changes (lookup-intent). |
| 3753 | */ |
| 3754 | static int |
| 3755 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3756 | struct iattr *sattr) |
| 3757 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3758 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3759 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3760 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3761 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | int status; |
| 3763 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3764 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3765 | sattr->ia_valid & ATTR_SIZE && |
| 3766 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3767 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3768 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3769 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3771 | /* Deal with open(O_TRUNC) */ |
| 3772 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3773 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3774 | |
| 3775 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3776 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3777 | return 0; |
| 3778 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3779 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3780 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3781 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3782 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3783 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3784 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3785 | } |
| 3786 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3787 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3788 | if (IS_ERR(label)) |
| 3789 | return PTR_ERR(label); |
| 3790 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3791 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3792 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3793 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3794 | nfs_setsecurity(inode, fattr, label); |
| 3795 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3796 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | return status; |
| 3798 | } |
| 3799 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3800 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3801 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3802 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3803 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3804 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3805 | int status; |
| 3806 | struct nfs4_lookup_arg args = { |
| 3807 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3808 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3809 | .name = name, |
| 3810 | }; |
| 3811 | struct nfs4_lookup_res res = { |
| 3812 | .server = server, |
| 3813 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3814 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3815 | .fh = fhandle, |
| 3816 | }; |
| 3817 | struct rpc_message msg = { |
| 3818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3819 | .rpc_argp = &args, |
| 3820 | .rpc_resp = &res, |
| 3821 | }; |
| 3822 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3823 | args.bitmask = nfs4_bitmask(server, label); |
| 3824 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3825 | nfs_fattr_init(fattr); |
| 3826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3828 | 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] | 3829 | dprintk("NFS reply lookup: %d\n", status); |
| 3830 | return status; |
| 3831 | } |
| 3832 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3833 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3834 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3835 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3836 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3837 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3838 | fattr->nlink = 2; |
| 3839 | } |
| 3840 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3841 | 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] | 3842 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3843 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3844 | { |
| 3845 | struct nfs4_exception exception = { }; |
| 3846 | struct rpc_clnt *client = *clnt; |
| 3847 | int err; |
| 3848 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3849 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3850 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3851 | switch (err) { |
| 3852 | case -NFS4ERR_BADNAME: |
| 3853 | err = -ENOENT; |
| 3854 | goto out; |
| 3855 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3856 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3857 | if (err == -NFS4ERR_MOVED) |
| 3858 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3859 | goto out; |
| 3860 | case -NFS4ERR_WRONGSEC: |
| 3861 | err = -EPERM; |
| 3862 | if (client != *clnt) |
| 3863 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3864 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3865 | if (IS_ERR(client)) |
| 3866 | return PTR_ERR(client); |
| 3867 | |
| 3868 | exception.retry = 1; |
| 3869 | break; |
| 3870 | default: |
| 3871 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3872 | } |
| 3873 | } while (exception.retry); |
| 3874 | |
| 3875 | out: |
| 3876 | if (err == 0) |
| 3877 | *clnt = client; |
| 3878 | else if (client != *clnt) |
| 3879 | rpc_shutdown_client(client); |
| 3880 | |
| 3881 | return err; |
| 3882 | } |
| 3883 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3884 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3885 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3886 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3888 | int status; |
| 3889 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [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, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3892 | if (client != NFS_CLIENT(dir)) { |
| 3893 | rpc_shutdown_client(client); |
| 3894 | nfs_fixup_secinfo_attributes(fattr); |
| 3895 | } |
| 3896 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | } |
| 3898 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3899 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3900 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3901 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3902 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3903 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3904 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3905 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3906 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3907 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3908 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3909 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3910 | } |
| 3911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3913 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3914 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | struct nfs4_accessargs args = { |
| 3916 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3917 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3919 | struct nfs4_accessres res = { |
| 3920 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3921 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | struct rpc_message msg = { |
| 3923 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3924 | .rpc_argp = &args, |
| 3925 | .rpc_resp = &res, |
| 3926 | .rpc_cred = entry->cred, |
| 3927 | }; |
| 3928 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3929 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | |
| 3931 | /* |
| 3932 | * Determine which access bits we want to ask for... |
| 3933 | */ |
| 3934 | if (mode & MAY_READ) |
| 3935 | args.access |= NFS4_ACCESS_READ; |
| 3936 | if (S_ISDIR(inode->i_mode)) { |
| 3937 | if (mode & MAY_WRITE) |
| 3938 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3939 | if (mode & MAY_EXEC) |
| 3940 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3941 | } else { |
| 3942 | if (mode & MAY_WRITE) |
| 3943 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3944 | if (mode & MAY_EXEC) |
| 3945 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3946 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3947 | |
| 3948 | res.fattr = nfs_alloc_fattr(); |
| 3949 | if (res.fattr == NULL) |
| 3950 | return -ENOMEM; |
| 3951 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3952 | 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] | 3953 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3954 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3955 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3957 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | return status; |
| 3959 | } |
| 3960 | |
| 3961 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3962 | { |
| 3963 | struct nfs4_exception exception = { }; |
| 3964 | int err; |
| 3965 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3966 | err = _nfs4_proc_access(inode, entry); |
| 3967 | trace_nfs4_access(inode, err); |
| 3968 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | &exception); |
| 3970 | } while (exception.retry); |
| 3971 | return err; |
| 3972 | } |
| 3973 | |
| 3974 | /* |
| 3975 | * TODO: For the time being, we don't try to get any attributes |
| 3976 | * along with any of the zero-copy operations READ, READDIR, |
| 3977 | * READLINK, WRITE. |
| 3978 | * |
| 3979 | * In the case of the first three, we want to put the GETATTR |
| 3980 | * after the read-type operation -- this is because it is hard |
| 3981 | * to predict the length of a GETATTR response in v4, and thus |
| 3982 | * align the READ data correctly. This means that the GETATTR |
| 3983 | * may end up partially falling into the page cache, and we should |
| 3984 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3985 | * To do this efficiently, we need to know the total length |
| 3986 | * of data received, which doesn't seem to be available outside |
| 3987 | * of the RPC layer. |
| 3988 | * |
| 3989 | * In the case of WRITE, we also want to put the GETATTR after |
| 3990 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3991 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | * |
| 3993 | * Both of these changes to the XDR layer would in fact be quite |
| 3994 | * minor, but I decided to leave them for a subsequent patch. |
| 3995 | */ |
| 3996 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3997 | unsigned int pgbase, unsigned int pglen) |
| 3998 | { |
| 3999 | struct nfs4_readlink args = { |
| 4000 | .fh = NFS_FH(inode), |
| 4001 | .pgbase = pgbase, |
| 4002 | .pglen = pglen, |
| 4003 | .pages = &page, |
| 4004 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4005 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | struct rpc_message msg = { |
| 4007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4008 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4009 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | }; |
| 4011 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4012 | 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] | 4013 | } |
| 4014 | |
| 4015 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4016 | unsigned int pgbase, unsigned int pglen) |
| 4017 | { |
| 4018 | struct nfs4_exception exception = { }; |
| 4019 | int err; |
| 4020 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4021 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4022 | trace_nfs4_readlink(inode, err); |
| 4023 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | &exception); |
| 4025 | } while (exception.retry); |
| 4026 | return err; |
| 4027 | } |
| 4028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4030 | * 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] | 4031 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | static int |
| 4033 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4034 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4036 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4037 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4038 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | int status = 0; |
| 4041 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4042 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4043 | if (IS_ERR(ctx)) |
| 4044 | return PTR_ERR(ctx); |
| 4045 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4046 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4047 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4048 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4049 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4050 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | if (IS_ERR(state)) { |
| 4052 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4053 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4056 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4057 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | return status; |
| 4059 | } |
| 4060 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4061 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4063 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4064 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4066 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4068 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4069 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4070 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4072 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4073 | .rpc_argp = &args, |
| 4074 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4076 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4077 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4078 | 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] | 4079 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4080 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | return status; |
| 4082 | } |
| 4083 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4084 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | { |
| 4086 | struct nfs4_exception exception = { }; |
| 4087 | int err; |
| 4088 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4089 | err = _nfs4_proc_remove(dir, name); |
| 4090 | trace_nfs4_remove(dir, name, err); |
| 4091 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | &exception); |
| 4093 | } while (exception.retry); |
| 4094 | return err; |
| 4095 | } |
| 4096 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4097 | 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] | 4098 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4099 | struct nfs_server *server = NFS_SERVER(dir); |
| 4100 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4101 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4103 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4105 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4106 | |
| 4107 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4110 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4111 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4112 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4113 | &data->args.seq_args, |
| 4114 | &data->res.seq_res, |
| 4115 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4118 | 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] | 4119 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4120 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4121 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4122 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4123 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4124 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4125 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4126 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4127 | return 0; |
| 4128 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4129 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4132 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4133 | { |
| 4134 | struct nfs_server *server = NFS_SERVER(dir); |
| 4135 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4136 | struct nfs_renameres *res = msg->rpc_resp; |
| 4137 | |
| 4138 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4139 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4140 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4141 | } |
| 4142 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4143 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4144 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4145 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4146 | &data->args.seq_args, |
| 4147 | &data->res.seq_res, |
| 4148 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4152 | struct inode *new_dir) |
| 4153 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4154 | struct nfs_renamedata *data = task->tk_calldata; |
| 4155 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4156 | |
| 4157 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4158 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4159 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4160 | return 0; |
| 4161 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame^] | 4162 | if (task->tk_status == 0) { |
| 4163 | update_changeattr(old_dir, &res->old_cinfo); |
| 4164 | if (new_dir != old_dir) |
| 4165 | update_changeattr(new_dir, &res->new_cinfo); |
| 4166 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4167 | return 1; |
| 4168 | } |
| 4169 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4170 | 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] | 4171 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4172 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | struct nfs4_link_arg arg = { |
| 4174 | .fh = NFS_FH(inode), |
| 4175 | .dir_fh = NFS_FH(dir), |
| 4176 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4177 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4179 | struct nfs4_link_res res = { |
| 4180 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4181 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4182 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | struct rpc_message msg = { |
| 4184 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4185 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4186 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4188 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4190 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4191 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4192 | goto out; |
| 4193 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4194 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4195 | if (IS_ERR(res.label)) { |
| 4196 | status = PTR_ERR(res.label); |
| 4197 | goto out; |
| 4198 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4199 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4200 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4201 | 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] | 4202 | if (!status) { |
| 4203 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4204 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4205 | if (!status) |
| 4206 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4207 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4208 | |
| 4209 | |
| 4210 | nfs4_label_free(res.label); |
| 4211 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4212 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4213 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | return status; |
| 4215 | } |
| 4216 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4217 | 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] | 4218 | { |
| 4219 | struct nfs4_exception exception = { }; |
| 4220 | int err; |
| 4221 | do { |
| 4222 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4223 | _nfs4_proc_link(inode, dir, name), |
| 4224 | &exception); |
| 4225 | } while (exception.retry); |
| 4226 | return err; |
| 4227 | } |
| 4228 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4229 | struct nfs4_createdata { |
| 4230 | struct rpc_message msg; |
| 4231 | struct nfs4_create_arg arg; |
| 4232 | struct nfs4_create_res res; |
| 4233 | struct nfs_fh fh; |
| 4234 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4235 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4236 | }; |
| 4237 | |
| 4238 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4239 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4240 | { |
| 4241 | struct nfs4_createdata *data; |
| 4242 | |
| 4243 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4244 | if (data != NULL) { |
| 4245 | struct nfs_server *server = NFS_SERVER(dir); |
| 4246 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4247 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4248 | if (IS_ERR(data->label)) |
| 4249 | goto out_free; |
| 4250 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4251 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4252 | data->msg.rpc_argp = &data->arg; |
| 4253 | data->msg.rpc_resp = &data->res; |
| 4254 | data->arg.dir_fh = NFS_FH(dir); |
| 4255 | data->arg.server = server; |
| 4256 | data->arg.name = name; |
| 4257 | data->arg.attrs = sattr; |
| 4258 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4259 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4260 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4261 | data->res.server = server; |
| 4262 | data->res.fh = &data->fh; |
| 4263 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4264 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4265 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4266 | } |
| 4267 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4268 | out_free: |
| 4269 | kfree(data); |
| 4270 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4274 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4275 | 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] | 4276 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4277 | if (status == 0) { |
| 4278 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4279 | 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] | 4280 | } |
| 4281 | return status; |
| 4282 | } |
| 4283 | |
| 4284 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4285 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4286 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4287 | kfree(data); |
| 4288 | } |
| 4289 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4290 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4291 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4292 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4294 | struct nfs4_createdata *data; |
| 4295 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4297 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4298 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4299 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4300 | status = -ENOMEM; |
| 4301 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4302 | if (data == NULL) |
| 4303 | goto out; |
| 4304 | |
| 4305 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4306 | data->arg.u.symlink.pages = &page; |
| 4307 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4308 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4310 | status = nfs4_do_create(dir, dentry, data); |
| 4311 | |
| 4312 | nfs4_free_createdata(data); |
| 4313 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | return status; |
| 4315 | } |
| 4316 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4317 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4318 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | { |
| 4320 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4321 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4323 | |
| 4324 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4327 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4328 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4329 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | &exception); |
| 4331 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4332 | |
| 4333 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | return err; |
| 4335 | } |
| 4336 | |
| 4337 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4338 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4340 | struct nfs4_createdata *data; |
| 4341 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4343 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4344 | if (data == NULL) |
| 4345 | goto out; |
| 4346 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4347 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4348 | status = nfs4_do_create(dir, dentry, data); |
| 4349 | |
| 4350 | nfs4_free_createdata(data); |
| 4351 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | return status; |
| 4353 | } |
| 4354 | |
| 4355 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4356 | struct iattr *sattr) |
| 4357 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4358 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4360 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4362 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4363 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4364 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4365 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4366 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4368 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4369 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4370 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | &exception); |
| 4372 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4373 | nfs4_label_release_security(label); |
| 4374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | return err; |
| 4376 | } |
| 4377 | |
| 4378 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4379 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4381 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | struct nfs4_readdir_arg args = { |
| 4383 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4384 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | .pgbase = 0, |
| 4386 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4387 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4388 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | }; |
| 4390 | struct nfs4_readdir_res res; |
| 4391 | struct rpc_message msg = { |
| 4392 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4393 | .rpc_argp = &args, |
| 4394 | .rpc_resp = &res, |
| 4395 | .rpc_cred = cred, |
| 4396 | }; |
| 4397 | int status; |
| 4398 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4399 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4400 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4401 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4402 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4404 | 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] | 4405 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4406 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4407 | status += args.pgbase; |
| 4408 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4409 | |
| 4410 | nfs_invalidate_atime(dir); |
| 4411 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4412 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | return status; |
| 4414 | } |
| 4415 | |
| 4416 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4417 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | { |
| 4419 | struct nfs4_exception exception = { }; |
| 4420 | int err; |
| 4421 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4422 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4423 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4424 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4425 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | &exception); |
| 4427 | } while (exception.retry); |
| 4428 | return err; |
| 4429 | } |
| 4430 | |
| 4431 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4432 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4434 | struct nfs4_createdata *data; |
| 4435 | int mode = sattr->ia_mode; |
| 4436 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4438 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4439 | if (data == NULL) |
| 4440 | goto out; |
| 4441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4443 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4445 | data->arg.ftype = NF4BLK; |
| 4446 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4447 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | } |
| 4449 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4450 | data->arg.ftype = NF4CHR; |
| 4451 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4452 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4453 | } else if (!S_ISSOCK(mode)) { |
| 4454 | status = -EINVAL; |
| 4455 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4457 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4458 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4459 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4460 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4461 | nfs4_free_createdata(data); |
| 4462 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | return status; |
| 4464 | } |
| 4465 | |
| 4466 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4467 | struct iattr *sattr, dev_t rdev) |
| 4468 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4469 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4471 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4473 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4474 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4475 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4476 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4477 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4479 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4480 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4481 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | &exception); |
| 4483 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4484 | |
| 4485 | nfs4_label_release_security(label); |
| 4486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | return err; |
| 4488 | } |
| 4489 | |
| 4490 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4491 | struct nfs_fsstat *fsstat) |
| 4492 | { |
| 4493 | struct nfs4_statfs_arg args = { |
| 4494 | .fh = fhandle, |
| 4495 | .bitmask = server->attr_bitmask, |
| 4496 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4497 | struct nfs4_statfs_res res = { |
| 4498 | .fsstat = fsstat, |
| 4499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | struct rpc_message msg = { |
| 4501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4502 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4503 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | }; |
| 4505 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4506 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4507 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4511 | { |
| 4512 | struct nfs4_exception exception = { }; |
| 4513 | int err; |
| 4514 | do { |
| 4515 | err = nfs4_handle_exception(server, |
| 4516 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4517 | &exception); |
| 4518 | } while (exception.retry); |
| 4519 | return err; |
| 4520 | } |
| 4521 | |
| 4522 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4523 | struct nfs_fsinfo *fsinfo) |
| 4524 | { |
| 4525 | struct nfs4_fsinfo_arg args = { |
| 4526 | .fh = fhandle, |
| 4527 | .bitmask = server->attr_bitmask, |
| 4528 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4529 | struct nfs4_fsinfo_res res = { |
| 4530 | .fsinfo = fsinfo, |
| 4531 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | struct rpc_message msg = { |
| 4533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4534 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4535 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | }; |
| 4537 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4538 | 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] | 4539 | } |
| 4540 | |
| 4541 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4542 | { |
| 4543 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4544 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | int err; |
| 4546 | |
| 4547 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4548 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4549 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4550 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4551 | nfs4_set_lease_period(server->nfs_client, |
| 4552 | fsinfo->lease_time * HZ, |
| 4553 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4554 | break; |
| 4555 | } |
| 4556 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } while (exception.retry); |
| 4558 | return err; |
| 4559 | } |
| 4560 | |
| 4561 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4562 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4563 | int error; |
| 4564 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4565 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4566 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4567 | if (error == 0) { |
| 4568 | /* block layout checks this! */ |
| 4569 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4570 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4571 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4572 | |
| 4573 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4577 | struct nfs_pathconf *pathconf) |
| 4578 | { |
| 4579 | struct nfs4_pathconf_arg args = { |
| 4580 | .fh = fhandle, |
| 4581 | .bitmask = server->attr_bitmask, |
| 4582 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4583 | struct nfs4_pathconf_res res = { |
| 4584 | .pathconf = pathconf, |
| 4585 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | struct rpc_message msg = { |
| 4587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4588 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4589 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | }; |
| 4591 | |
| 4592 | /* None of the pathconf attributes are mandatory to implement */ |
| 4593 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4594 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4595 | return 0; |
| 4596 | } |
| 4597 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4598 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4599 | 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] | 4600 | } |
| 4601 | |
| 4602 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4603 | struct nfs_pathconf *pathconf) |
| 4604 | { |
| 4605 | struct nfs4_exception exception = { }; |
| 4606 | int err; |
| 4607 | |
| 4608 | do { |
| 4609 | err = nfs4_handle_exception(server, |
| 4610 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4611 | &exception); |
| 4612 | } while (exception.retry); |
| 4613 | return err; |
| 4614 | } |
| 4615 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4616 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4617 | const struct nfs_open_context *ctx, |
| 4618 | const struct nfs_lock_context *l_ctx, |
| 4619 | fmode_t fmode) |
| 4620 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4621 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4622 | } |
| 4623 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4624 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4625 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4626 | const struct nfs_open_context *ctx, |
| 4627 | const struct nfs_lock_context *l_ctx, |
| 4628 | fmode_t fmode) |
| 4629 | { |
| 4630 | nfs4_stateid current_stateid; |
| 4631 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4632 | /* If the current stateid represents a lost lock, then exit */ |
| 4633 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4634 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4635 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4636 | } |
| 4637 | |
| 4638 | static bool nfs4_error_stateid_expired(int err) |
| 4639 | { |
| 4640 | switch (err) { |
| 4641 | case -NFS4ERR_DELEG_REVOKED: |
| 4642 | case -NFS4ERR_ADMIN_REVOKED: |
| 4643 | case -NFS4ERR_BAD_STATEID: |
| 4644 | case -NFS4ERR_STALE_STATEID: |
| 4645 | case -NFS4ERR_OLD_STATEID: |
| 4646 | case -NFS4ERR_OPENMODE: |
| 4647 | case -NFS4ERR_EXPIRED: |
| 4648 | return true; |
| 4649 | } |
| 4650 | return false; |
| 4651 | } |
| 4652 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4653 | 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] | 4654 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4655 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4657 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4658 | if (task->tk_status < 0) { |
| 4659 | struct nfs4_exception exception = { |
| 4660 | .inode = hdr->inode, |
| 4661 | .state = hdr->args.context->state, |
| 4662 | .stateid = &hdr->args.stateid, |
| 4663 | }; |
| 4664 | task->tk_status = nfs4_async_handle_exception(task, |
| 4665 | server, task->tk_status, &exception); |
| 4666 | if (exception.retry) { |
| 4667 | rpc_restart_call_prepare(task); |
| 4668 | return -EAGAIN; |
| 4669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4673 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4674 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | } |
| 4676 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4677 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4678 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4679 | { |
| 4680 | |
| 4681 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4682 | nfs4_stateid_is_current(&args->stateid, |
| 4683 | args->context, |
| 4684 | args->lock_context, |
| 4685 | FMODE_READ)) |
| 4686 | return false; |
| 4687 | rpc_restart_call_prepare(task); |
| 4688 | return true; |
| 4689 | } |
| 4690 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4691 | 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] | 4692 | { |
| 4693 | |
| 4694 | dprintk("--> %s\n", __func__); |
| 4695 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4696 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4697 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4698 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4699 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4700 | if (task->tk_status > 0) |
| 4701 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4703 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4704 | } |
| 4705 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4706 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4707 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4709 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4710 | if (!hdr->pgio_done_cb) |
| 4711 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4712 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4713 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4716 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4717 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4718 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4719 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4720 | &hdr->args.seq_args, |
| 4721 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4722 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4723 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4724 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4725 | hdr->args.lock_context, |
| 4726 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4727 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4728 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4729 | return -EIO; |
| 4730 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4733 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4734 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4736 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4737 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4738 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4739 | if (task->tk_status < 0) { |
| 4740 | struct nfs4_exception exception = { |
| 4741 | .inode = hdr->inode, |
| 4742 | .state = hdr->args.context->state, |
| 4743 | .stateid = &hdr->args.stateid, |
| 4744 | }; |
| 4745 | task->tk_status = nfs4_async_handle_exception(task, |
| 4746 | NFS_SERVER(inode), task->tk_status, |
| 4747 | &exception); |
| 4748 | if (exception.retry) { |
| 4749 | rpc_restart_call_prepare(task); |
| 4750 | return -EAGAIN; |
| 4751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4753 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4754 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4755 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4756 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4757 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4760 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4761 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4762 | { |
| 4763 | |
| 4764 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4765 | nfs4_stateid_is_current(&args->stateid, |
| 4766 | args->context, |
| 4767 | args->lock_context, |
| 4768 | FMODE_WRITE)) |
| 4769 | return false; |
| 4770 | rpc_restart_call_prepare(task); |
| 4771 | return true; |
| 4772 | } |
| 4773 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4774 | 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] | 4775 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4776 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4777 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4778 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4779 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4780 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4781 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4784 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4785 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4786 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4787 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4788 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4789 | return false; |
| 4790 | /* Otherwise, request attributes if and only if we don't hold |
| 4791 | * a delegation |
| 4792 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4793 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4794 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4795 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4796 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4797 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4799 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4800 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4801 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4802 | hdr->args.bitmask = NULL; |
| 4803 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4804 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4805 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4806 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4807 | if (!hdr->pgio_done_cb) |
| 4808 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4809 | hdr->res.server = server; |
| 4810 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4812 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4813 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4816 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4817 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4818 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4819 | &data->args.seq_args, |
| 4820 | &data->res.seq_res, |
| 4821 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4824 | 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] | 4825 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4827 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4828 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4829 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4830 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4831 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4832 | return -EAGAIN; |
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 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4837 | 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] | 4838 | { |
| 4839 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4840 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4841 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4842 | } |
| 4843 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4844 | 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] | 4845 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4846 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4847 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4848 | if (data->commit_done_cb == NULL) |
| 4849 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4850 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4851 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4852 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4855 | struct nfs4_renewdata { |
| 4856 | struct nfs_client *client; |
| 4857 | unsigned long timestamp; |
| 4858 | }; |
| 4859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | /* |
| 4861 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4862 | * standalone procedure for queueing an asynchronous RENEW. |
| 4863 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4864 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4865 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4866 | struct nfs4_renewdata *data = calldata; |
| 4867 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4868 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4869 | if (atomic_read(&clp->cl_count) > 1) |
| 4870 | nfs4_schedule_state_renewal(clp); |
| 4871 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4872 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4875 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4877 | struct nfs4_renewdata *data = calldata; |
| 4878 | struct nfs_client *clp = data->client; |
| 4879 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4881 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4882 | switch (task->tk_status) { |
| 4883 | case 0: |
| 4884 | break; |
| 4885 | case -NFS4ERR_LEASE_MOVED: |
| 4886 | nfs4_schedule_lease_moved_recovery(clp); |
| 4887 | break; |
| 4888 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4889 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4890 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4891 | return; |
| 4892 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4893 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4894 | return; |
| 4895 | } |
| 4896 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4898 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4901 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4902 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4903 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4904 | }; |
| 4905 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4906 | 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] | 4907 | { |
| 4908 | struct rpc_message msg = { |
| 4909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4910 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4911 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4913 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4915 | if (renew_flags == 0) |
| 4916 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4917 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4918 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4919 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4920 | if (data == NULL) |
| 4921 | return -ENOMEM; |
| 4922 | data->client = clp; |
| 4923 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4924 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4925 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4928 | 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] | 4929 | { |
| 4930 | struct rpc_message msg = { |
| 4931 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4932 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4933 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | }; |
| 4935 | unsigned long now = jiffies; |
| 4936 | int status; |
| 4937 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4938 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | if (status < 0) |
| 4940 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4941 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | return 0; |
| 4943 | } |
| 4944 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4945 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4946 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4947 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4948 | } |
| 4949 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4950 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4951 | * 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] | 4952 | * the stack. |
| 4953 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4954 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4955 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4956 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4957 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4958 | { |
| 4959 | struct page *newpage, **spages; |
| 4960 | int rc = 0; |
| 4961 | size_t len; |
| 4962 | spages = pages; |
| 4963 | |
| 4964 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4965 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4966 | newpage = alloc_page(GFP_KERNEL); |
| 4967 | |
| 4968 | if (newpage == NULL) |
| 4969 | goto unwind; |
| 4970 | memcpy(page_address(newpage), buf, len); |
| 4971 | buf += len; |
| 4972 | buflen -= len; |
| 4973 | *pages++ = newpage; |
| 4974 | rc++; |
| 4975 | } while (buflen != 0); |
| 4976 | |
| 4977 | return rc; |
| 4978 | |
| 4979 | unwind: |
| 4980 | for(; rc > 0; rc--) |
| 4981 | __free_page(spages[rc-1]); |
| 4982 | return -ENOMEM; |
| 4983 | } |
| 4984 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4985 | struct nfs4_cached_acl { |
| 4986 | int cached; |
| 4987 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4988 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4989 | }; |
| 4990 | |
| 4991 | 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] | 4992 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4993 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4994 | |
| 4995 | spin_lock(&inode->i_lock); |
| 4996 | kfree(nfsi->nfs4_acl); |
| 4997 | nfsi->nfs4_acl = acl; |
| 4998 | spin_unlock(&inode->i_lock); |
| 4999 | } |
| 5000 | |
| 5001 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5002 | { |
| 5003 | nfs4_set_cached_acl(inode, NULL); |
| 5004 | } |
| 5005 | |
| 5006 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5007 | { |
| 5008 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5009 | struct nfs4_cached_acl *acl; |
| 5010 | int ret = -ENOENT; |
| 5011 | |
| 5012 | spin_lock(&inode->i_lock); |
| 5013 | acl = nfsi->nfs4_acl; |
| 5014 | if (acl == NULL) |
| 5015 | goto out; |
| 5016 | if (buf == NULL) /* user is just asking for length */ |
| 5017 | goto out_len; |
| 5018 | if (acl->cached == 0) |
| 5019 | goto out; |
| 5020 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5021 | if (acl->len > buflen) |
| 5022 | goto out; |
| 5023 | memcpy(buf, acl->data, acl->len); |
| 5024 | out_len: |
| 5025 | ret = acl->len; |
| 5026 | out: |
| 5027 | spin_unlock(&inode->i_lock); |
| 5028 | return ret; |
| 5029 | } |
| 5030 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5031 | 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] | 5032 | { |
| 5033 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5034 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5035 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5036 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5037 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5038 | if (acl == NULL) |
| 5039 | goto out; |
| 5040 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5041 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5042 | } else { |
| 5043 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5044 | if (acl == NULL) |
| 5045 | goto out; |
| 5046 | acl->cached = 0; |
| 5047 | } |
| 5048 | acl->len = acl_len; |
| 5049 | out: |
| 5050 | nfs4_set_cached_acl(inode, acl); |
| 5051 | } |
| 5052 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5053 | /* |
| 5054 | * The getxattr API returns the required buffer length when called with a |
| 5055 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5056 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5057 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5058 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5059 | * the cache. If not so, we throw away the page, and cache the required |
| 5060 | * length. The next getxattr call will then produce another round trip to |
| 5061 | * the server, this time with the input buf of the required size. |
| 5062 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5063 | 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] | 5064 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5065 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5066 | struct nfs_getaclargs args = { |
| 5067 | .fh = NFS_FH(inode), |
| 5068 | .acl_pages = pages, |
| 5069 | .acl_len = buflen, |
| 5070 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5071 | struct nfs_getaclres res = { |
| 5072 | .acl_len = buflen, |
| 5073 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5074 | struct rpc_message msg = { |
| 5075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5076 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5077 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5078 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5079 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5080 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5081 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5082 | /* As long as we're doing a round trip to the server anyway, |
| 5083 | * let's be prepared for a page of acl data. */ |
| 5084 | if (npages == 0) |
| 5085 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5086 | if (npages > ARRAY_SIZE(pages)) |
| 5087 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5088 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5089 | for (i = 0; i < npages; i++) { |
| 5090 | pages[i] = alloc_page(GFP_KERNEL); |
| 5091 | if (!pages[i]) |
| 5092 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5093 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5094 | |
| 5095 | /* for decoding across pages */ |
| 5096 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5097 | if (!res.acl_scratch) |
| 5098 | goto out_free; |
| 5099 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5100 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5101 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5102 | 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] | 5103 | __func__, buf, buflen, npages, args.acl_len); |
| 5104 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5105 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5106 | if (ret) |
| 5107 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5108 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5109 | /* Handle the case where the passed-in buffer is too short */ |
| 5110 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5111 | /* Did the user only issue a request for the acl length? */ |
| 5112 | if (buf == NULL) |
| 5113 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5114 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5115 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5116 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5117 | 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] | 5118 | if (buf) { |
| 5119 | if (res.acl_len > buflen) { |
| 5120 | ret = -ERANGE; |
| 5121 | goto out_free; |
| 5122 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5123 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5124 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5125 | out_ok: |
| 5126 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5127 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5128 | for (i = 0; i < npages; i++) |
| 5129 | if (pages[i]) |
| 5130 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5131 | if (res.acl_scratch) |
| 5132 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5133 | return ret; |
| 5134 | } |
| 5135 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5136 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5137 | { |
| 5138 | struct nfs4_exception exception = { }; |
| 5139 | ssize_t ret; |
| 5140 | do { |
| 5141 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5142 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5143 | if (ret >= 0) |
| 5144 | break; |
| 5145 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5146 | } while (exception.retry); |
| 5147 | return ret; |
| 5148 | } |
| 5149 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5150 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5151 | { |
| 5152 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5153 | int ret; |
| 5154 | |
| 5155 | if (!nfs4_server_supports_acls(server)) |
| 5156 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5157 | ret = nfs_revalidate_inode(server, inode); |
| 5158 | if (ret < 0) |
| 5159 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5160 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5161 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5162 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5163 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5164 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5165 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5166 | return ret; |
| 5167 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5170 | 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] | 5171 | { |
| 5172 | struct nfs_server *server = NFS_SERVER(inode); |
| 5173 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5174 | struct nfs_setaclargs arg = { |
| 5175 | .fh = NFS_FH(inode), |
| 5176 | .acl_pages = pages, |
| 5177 | .acl_len = buflen, |
| 5178 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5179 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5180 | struct rpc_message msg = { |
| 5181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5182 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5183 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5184 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5185 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5186 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5187 | |
| 5188 | if (!nfs4_server_supports_acls(server)) |
| 5189 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5190 | if (npages > ARRAY_SIZE(pages)) |
| 5191 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5192 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5193 | if (i < 0) |
| 5194 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5195 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5196 | 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] | 5197 | |
| 5198 | /* |
| 5199 | * Free each page after tx, so the only ref left is |
| 5200 | * held by the network stack |
| 5201 | */ |
| 5202 | for (; i > 0; i--) |
| 5203 | put_page(pages[i-1]); |
| 5204 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5205 | /* |
| 5206 | * Acl update can result in inode attribute update. |
| 5207 | * so mark the attribute cache invalid. |
| 5208 | */ |
| 5209 | spin_lock(&inode->i_lock); |
| 5210 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5211 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5212 | nfs_access_zap_cache(inode); |
| 5213 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5214 | return ret; |
| 5215 | } |
| 5216 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5217 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5218 | { |
| 5219 | struct nfs4_exception exception = { }; |
| 5220 | int err; |
| 5221 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5222 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5223 | trace_nfs4_set_acl(inode, err); |
| 5224 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5225 | &exception); |
| 5226 | } while (exception.retry); |
| 5227 | return err; |
| 5228 | } |
| 5229 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5230 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5231 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5232 | size_t buflen) |
| 5233 | { |
| 5234 | struct nfs_server *server = NFS_SERVER(inode); |
| 5235 | struct nfs_fattr fattr; |
| 5236 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5237 | |
| 5238 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5239 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5240 | .fh = NFS_FH(inode), |
| 5241 | .bitmask = bitmask, |
| 5242 | }; |
| 5243 | struct nfs4_getattr_res res = { |
| 5244 | .fattr = &fattr, |
| 5245 | .label = &label, |
| 5246 | .server = server, |
| 5247 | }; |
| 5248 | struct rpc_message msg = { |
| 5249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5250 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5251 | .rpc_resp = &res, |
| 5252 | }; |
| 5253 | int ret; |
| 5254 | |
| 5255 | nfs_fattr_init(&fattr); |
| 5256 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5257 | 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] | 5258 | if (ret) |
| 5259 | return ret; |
| 5260 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5261 | return -ENOENT; |
| 5262 | if (buflen < label.len) |
| 5263 | return -ERANGE; |
| 5264 | return 0; |
| 5265 | } |
| 5266 | |
| 5267 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5268 | size_t buflen) |
| 5269 | { |
| 5270 | struct nfs4_exception exception = { }; |
| 5271 | int err; |
| 5272 | |
| 5273 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5274 | return -EOPNOTSUPP; |
| 5275 | |
| 5276 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5277 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5278 | trace_nfs4_get_security_label(inode, err); |
| 5279 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5280 | &exception); |
| 5281 | } while (exception.retry); |
| 5282 | return err; |
| 5283 | } |
| 5284 | |
| 5285 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5286 | struct nfs4_label *ilabel, |
| 5287 | struct nfs_fattr *fattr, |
| 5288 | struct nfs4_label *olabel) |
| 5289 | { |
| 5290 | |
| 5291 | struct iattr sattr = {0}; |
| 5292 | struct nfs_server *server = NFS_SERVER(inode); |
| 5293 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5294 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5295 | .fh = NFS_FH(inode), |
| 5296 | .iap = &sattr, |
| 5297 | .server = server, |
| 5298 | .bitmask = bitmask, |
| 5299 | .label = ilabel, |
| 5300 | }; |
| 5301 | struct nfs_setattrres res = { |
| 5302 | .fattr = fattr, |
| 5303 | .label = olabel, |
| 5304 | .server = server, |
| 5305 | }; |
| 5306 | struct rpc_message msg = { |
| 5307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5308 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5309 | .rpc_resp = &res, |
| 5310 | }; |
| 5311 | int status; |
| 5312 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5313 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5314 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5315 | 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] | 5316 | if (status) |
| 5317 | dprintk("%s failed: %d\n", __func__, status); |
| 5318 | |
| 5319 | return status; |
| 5320 | } |
| 5321 | |
| 5322 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5323 | struct nfs4_label *ilabel, |
| 5324 | struct nfs_fattr *fattr, |
| 5325 | struct nfs4_label *olabel) |
| 5326 | { |
| 5327 | struct nfs4_exception exception = { }; |
| 5328 | int err; |
| 5329 | |
| 5330 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5331 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5332 | fattr, olabel); |
| 5333 | trace_nfs4_set_security_label(inode, err); |
| 5334 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5335 | &exception); |
| 5336 | } while (exception.retry); |
| 5337 | return err; |
| 5338 | } |
| 5339 | |
| 5340 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5341 | 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] | 5342 | { |
| 5343 | struct nfs4_label ilabel, *olabel = NULL; |
| 5344 | struct nfs_fattr fattr; |
| 5345 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5346 | int status; |
| 5347 | |
| 5348 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5349 | return -EOPNOTSUPP; |
| 5350 | |
| 5351 | nfs_fattr_init(&fattr); |
| 5352 | |
| 5353 | ilabel.pi = 0; |
| 5354 | ilabel.lfs = 0; |
| 5355 | ilabel.label = (char *)buf; |
| 5356 | ilabel.len = buflen; |
| 5357 | |
| 5358 | cred = rpc_lookup_cred(); |
| 5359 | if (IS_ERR(cred)) |
| 5360 | return PTR_ERR(cred); |
| 5361 | |
| 5362 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5363 | if (IS_ERR(olabel)) { |
| 5364 | status = -PTR_ERR(olabel); |
| 5365 | goto out; |
| 5366 | } |
| 5367 | |
| 5368 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5369 | if (status == 0) |
| 5370 | nfs_setsecurity(inode, &fattr, olabel); |
| 5371 | |
| 5372 | nfs4_label_free(olabel); |
| 5373 | out: |
| 5374 | put_rpccred(cred); |
| 5375 | return status; |
| 5376 | } |
| 5377 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5378 | |
| 5379 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5380 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5381 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5382 | { |
| 5383 | __be32 verf[2]; |
| 5384 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5385 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5386 | /* An impossible timestamp guarantees this value |
| 5387 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5388 | verf[0] = cpu_to_be32(U32_MAX); |
| 5389 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5390 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5391 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5392 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5393 | |
| 5394 | verf[0] = cpu_to_be32(ns >> 32); |
| 5395 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5396 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5397 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5398 | } |
| 5399 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5400 | static int |
| 5401 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5402 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5403 | size_t len; |
| 5404 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5405 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5406 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5407 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5408 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5409 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5410 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5411 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5412 | 1 + |
| 5413 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5414 | 1; |
| 5415 | rcu_read_unlock(); |
| 5416 | |
| 5417 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5418 | return -EINVAL; |
| 5419 | |
| 5420 | /* |
| 5421 | * Since this string is allocated at mount time, and held until the |
| 5422 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5423 | * about a memory-reclaim deadlock. |
| 5424 | */ |
| 5425 | str = kmalloc(len, GFP_KERNEL); |
| 5426 | if (!str) |
| 5427 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5428 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5429 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5430 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5431 | clp->cl_ipaddr, |
| 5432 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5433 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5434 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5435 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5436 | clp->cl_owner_id = str; |
| 5437 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5438 | } |
| 5439 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5440 | static int |
| 5441 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5442 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5443 | size_t len; |
| 5444 | char *str; |
| 5445 | |
| 5446 | len = 10 + 10 + 1 + 10 + 1 + |
| 5447 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5448 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5449 | |
| 5450 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5451 | return -EINVAL; |
| 5452 | |
| 5453 | /* |
| 5454 | * Since this string is allocated at mount time, and held until the |
| 5455 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5456 | * about a memory-reclaim deadlock. |
| 5457 | */ |
| 5458 | str = kmalloc(len, GFP_KERNEL); |
| 5459 | if (!str) |
| 5460 | return -ENOMEM; |
| 5461 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5462 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5463 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5464 | nfs4_client_id_uniquifier, |
| 5465 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5466 | clp->cl_owner_id = str; |
| 5467 | return 0; |
| 5468 | } |
| 5469 | |
| 5470 | static int |
| 5471 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5472 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5473 | size_t len; |
| 5474 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5475 | |
| 5476 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5477 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5478 | |
| 5479 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5480 | return nfs4_init_uniquifier_client_string(clp); |
| 5481 | |
| 5482 | len = 10 + 10 + 1 + 10 + 1 + |
| 5483 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5484 | |
| 5485 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5486 | return -EINVAL; |
| 5487 | |
| 5488 | /* |
| 5489 | * Since this string is allocated at mount time, and held until the |
| 5490 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5491 | * about a memory-reclaim deadlock. |
| 5492 | */ |
| 5493 | str = kmalloc(len, GFP_KERNEL); |
| 5494 | if (!str) |
| 5495 | return -ENOMEM; |
| 5496 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5497 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5498 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5499 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5500 | clp->cl_owner_id = str; |
| 5501 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5502 | } |
| 5503 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5504 | /* |
| 5505 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5506 | * services. Advertise one based on the address family of the |
| 5507 | * clientaddr. |
| 5508 | */ |
| 5509 | static unsigned int |
| 5510 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5511 | { |
| 5512 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5513 | return scnprintf(buf, len, "tcp6"); |
| 5514 | else |
| 5515 | return scnprintf(buf, len, "tcp"); |
| 5516 | } |
| 5517 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5518 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5519 | { |
| 5520 | struct nfs4_setclientid *sc = calldata; |
| 5521 | |
| 5522 | if (task->tk_status == 0) |
| 5523 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5524 | } |
| 5525 | |
| 5526 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5527 | .rpc_call_done = nfs4_setclientid_done, |
| 5528 | }; |
| 5529 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5530 | /** |
| 5531 | * nfs4_proc_setclientid - Negotiate client ID |
| 5532 | * @clp: state data structure |
| 5533 | * @program: RPC program for NFSv4 callback service |
| 5534 | * @port: IP port number for NFS4 callback service |
| 5535 | * @cred: RPC credential to use for this call |
| 5536 | * @res: where to place the result |
| 5537 | * |
| 5538 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5539 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5540 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5541 | unsigned short port, struct rpc_cred *cred, |
| 5542 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | { |
| 5544 | nfs4_verifier sc_verifier; |
| 5545 | struct nfs4_setclientid setclientid = { |
| 5546 | .sc_verifier = &sc_verifier, |
| 5547 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5548 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | }; |
| 5550 | struct rpc_message msg = { |
| 5551 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5552 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5553 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5554 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5556 | struct rpc_task *task; |
| 5557 | struct rpc_task_setup task_setup_data = { |
| 5558 | .rpc_client = clp->cl_rpcclient, |
| 5559 | .rpc_message = &msg, |
| 5560 | .callback_ops = &nfs4_setclientid_ops, |
| 5561 | .callback_data = &setclientid, |
| 5562 | .flags = RPC_TASK_TIMEOUT, |
| 5563 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5564 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5566 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5567 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5568 | |
| 5569 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5570 | status = nfs4_init_uniform_client_string(clp); |
| 5571 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5572 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5573 | |
| 5574 | if (status) |
| 5575 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5576 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5577 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5578 | setclientid.sc_netid_len = |
| 5579 | nfs4_init_callback_netid(clp, |
| 5580 | setclientid.sc_netid, |
| 5581 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5582 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5583 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5585 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5586 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5587 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5588 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5589 | task = rpc_run_task(&task_setup_data); |
| 5590 | if (IS_ERR(task)) { |
| 5591 | status = PTR_ERR(task); |
| 5592 | goto out; |
| 5593 | } |
| 5594 | status = task->tk_status; |
| 5595 | if (setclientid.sc_cred) { |
| 5596 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5597 | put_rpccred(setclientid.sc_cred); |
| 5598 | } |
| 5599 | rpc_put_task(task); |
| 5600 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5601 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5602 | dprintk("NFS reply setclientid: %d\n", status); |
| 5603 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | } |
| 5605 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5606 | /** |
| 5607 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5608 | * @clp: state data structure |
| 5609 | * @res: result of a previous SETCLIENTID |
| 5610 | * @cred: RPC credential to use for this call |
| 5611 | * |
| 5612 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5613 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5614 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5615 | struct nfs4_setclientid_res *arg, |
| 5616 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | struct rpc_message msg = { |
| 5619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5620 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5621 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | int status; |
| 5624 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5625 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5626 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5627 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5628 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5629 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5630 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | return status; |
| 5632 | } |
| 5633 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5634 | struct nfs4_delegreturndata { |
| 5635 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5636 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5637 | struct nfs_fh fh; |
| 5638 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5639 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5640 | struct { |
| 5641 | struct nfs4_layoutreturn_args arg; |
| 5642 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5643 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5644 | u32 roc_barrier; |
| 5645 | bool roc; |
| 5646 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5647 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5648 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5649 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5650 | }; |
| 5651 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5652 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5653 | { |
| 5654 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5655 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5656 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5657 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5658 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5659 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5660 | |
| 5661 | /* Handle Layoutreturn errors */ |
| 5662 | if (data->args.lr_args && task->tk_status != 0) { |
| 5663 | switch(data->res.lr_ret) { |
| 5664 | default: |
| 5665 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5666 | break; |
| 5667 | case 0: |
| 5668 | data->args.lr_args = NULL; |
| 5669 | data->res.lr_res = NULL; |
| 5670 | break; |
| 5671 | case -NFS4ERR_ADMIN_REVOKED: |
| 5672 | case -NFS4ERR_DELEG_REVOKED: |
| 5673 | case -NFS4ERR_EXPIRED: |
| 5674 | case -NFS4ERR_BAD_STATEID: |
| 5675 | case -NFS4ERR_OLD_STATEID: |
| 5676 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5677 | case -NFS4ERR_WRONG_CRED: |
| 5678 | data->args.lr_args = NULL; |
| 5679 | data->res.lr_res = NULL; |
| 5680 | data->res.lr_ret = 0; |
| 5681 | rpc_restart_call_prepare(task); |
| 5682 | return; |
| 5683 | } |
| 5684 | } |
| 5685 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5686 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5687 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5688 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5689 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5690 | case -NFS4ERR_ADMIN_REVOKED: |
| 5691 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5692 | case -NFS4ERR_EXPIRED: |
| 5693 | nfs4_free_revoked_stateid(data->res.server, |
| 5694 | data->args.stateid, |
| 5695 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5696 | case -NFS4ERR_BAD_STATEID: |
| 5697 | case -NFS4ERR_OLD_STATEID: |
| 5698 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5699 | task->tk_status = 0; |
| 5700 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5701 | case -NFS4ERR_ACCESS: |
| 5702 | if (data->args.bitmask) { |
| 5703 | data->args.bitmask = NULL; |
| 5704 | data->res.fattr = NULL; |
| 5705 | task->tk_status = 0; |
| 5706 | rpc_restart_call_prepare(task); |
| 5707 | return; |
| 5708 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5709 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5710 | if (nfs4_async_handle_error(task, data->res.server, |
| 5711 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5712 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5713 | return; |
| 5714 | } |
| 5715 | } |
| 5716 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | static void nfs4_delegreturn_release(void *calldata) |
| 5720 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5721 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5722 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5723 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5724 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5725 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5726 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5727 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5728 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5729 | nfs_iput_and_deactive(inode); |
| 5730 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5731 | kfree(calldata); |
| 5732 | } |
| 5733 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5734 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5735 | { |
| 5736 | struct nfs4_delegreturndata *d_data; |
| 5737 | |
| 5738 | d_data = (struct nfs4_delegreturndata *)data; |
| 5739 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5740 | 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] | 5741 | return; |
| 5742 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5743 | nfs4_setup_sequence(d_data->res.server, |
| 5744 | &d_data->args.seq_args, |
| 5745 | &d_data->res.seq_res, |
| 5746 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5747 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5748 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5749 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5750 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5751 | .rpc_call_done = nfs4_delegreturn_done, |
| 5752 | .rpc_release = nfs4_delegreturn_release, |
| 5753 | }; |
| 5754 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5755 | 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] | 5756 | { |
| 5757 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5758 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5759 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5760 | struct rpc_message msg = { |
| 5761 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5762 | .rpc_cred = cred, |
| 5763 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5764 | struct rpc_task_setup task_setup_data = { |
| 5765 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5766 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5767 | .callback_ops = &nfs4_delegreturn_ops, |
| 5768 | .flags = RPC_TASK_ASYNC, |
| 5769 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5770 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5771 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5772 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5773 | if (data == NULL) |
| 5774 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5775 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5776 | |
| 5777 | nfs4_state_protect(server->nfs_client, |
| 5778 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5779 | &task_setup_data.rpc_client, &msg); |
| 5780 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5781 | data->args.fhandle = &data->fh; |
| 5782 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5783 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5784 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5785 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5786 | data->res.fattr = &data->fattr; |
| 5787 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5788 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5789 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5790 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5791 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5792 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5793 | 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] | 5794 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5795 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5796 | if (data->lr.roc) { |
| 5797 | data->args.lr_args = &data->lr.arg; |
| 5798 | data->res.lr_res = &data->lr.res; |
| 5799 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5800 | } else if (data->lr.roc) { |
| 5801 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5802 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5803 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5804 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5805 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5806 | msg.rpc_argp = &data->args; |
| 5807 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5808 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5809 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5810 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5811 | if (!issync) |
| 5812 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5813 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5814 | if (status != 0) |
| 5815 | goto out; |
| 5816 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5817 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5818 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5819 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5822 | 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] | 5823 | { |
| 5824 | struct nfs_server *server = NFS_SERVER(inode); |
| 5825 | struct nfs4_exception exception = { }; |
| 5826 | int err; |
| 5827 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5828 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5829 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5830 | switch (err) { |
| 5831 | case -NFS4ERR_STALE_STATEID: |
| 5832 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | case 0: |
| 5834 | return 0; |
| 5835 | } |
| 5836 | err = nfs4_handle_exception(server, err, &exception); |
| 5837 | } while (exception.retry); |
| 5838 | return err; |
| 5839 | } |
| 5840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5842 | { |
| 5843 | struct inode *inode = state->inode; |
| 5844 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5845 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5846 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5848 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5850 | struct nfs_lockt_res res = { |
| 5851 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | }; |
| 5853 | struct rpc_message msg = { |
| 5854 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5855 | .rpc_argp = &arg, |
| 5856 | .rpc_resp = &res, |
| 5857 | .rpc_cred = state->owner->so_cred, |
| 5858 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | struct nfs4_lock_state *lsp; |
| 5860 | int status; |
| 5861 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5862 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5863 | status = nfs4_set_lock_state(state, request); |
| 5864 | if (status != 0) |
| 5865 | goto out; |
| 5866 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5867 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5868 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5869 | 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] | 5870 | switch (status) { |
| 5871 | case 0: |
| 5872 | request->fl_type = F_UNLCK; |
| 5873 | break; |
| 5874 | case -NFS4ERR_DENIED: |
| 5875 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5877 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5878 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5879 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | return status; |
| 5881 | } |
| 5882 | |
| 5883 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5884 | { |
| 5885 | struct nfs4_exception exception = { }; |
| 5886 | int err; |
| 5887 | |
| 5888 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5889 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5890 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5891 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5892 | &exception); |
| 5893 | } while (exception.retry); |
| 5894 | return err; |
| 5895 | } |
| 5896 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5897 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5898 | struct nfs_locku_args arg; |
| 5899 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5900 | struct nfs4_lock_state *lsp; |
| 5901 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5902 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5903 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5904 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5905 | }; |
| 5906 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5907 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5908 | struct nfs_open_context *ctx, |
| 5909 | struct nfs4_lock_state *lsp, |
| 5910 | struct nfs_seqid *seqid) |
| 5911 | { |
| 5912 | struct nfs4_unlockdata *p; |
| 5913 | struct inode *inode = lsp->ls_state->inode; |
| 5914 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5915 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5916 | if (p == NULL) |
| 5917 | return NULL; |
| 5918 | p->arg.fh = NFS_FH(inode); |
| 5919 | p->arg.fl = &p->fl; |
| 5920 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5921 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5922 | p->lsp = lsp; |
| 5923 | atomic_inc(&lsp->ls_count); |
| 5924 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5925 | p->ctx = get_nfs_open_context(ctx); |
| 5926 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5927 | p->server = NFS_SERVER(inode); |
| 5928 | return p; |
| 5929 | } |
| 5930 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5931 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5932 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5933 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5934 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5935 | nfs4_put_lock_state(calldata->lsp); |
| 5936 | put_nfs_open_context(calldata->ctx); |
| 5937 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5938 | } |
| 5939 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5940 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5941 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5942 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5943 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5944 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5945 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5946 | switch (task->tk_status) { |
| 5947 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5948 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5949 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5950 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5951 | &calldata->res.stateid)) |
| 5952 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5953 | case -NFS4ERR_ADMIN_REVOKED: |
| 5954 | case -NFS4ERR_EXPIRED: |
| 5955 | nfs4_free_revoked_stateid(calldata->server, |
| 5956 | &calldata->arg.stateid, |
| 5957 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5958 | case -NFS4ERR_BAD_STATEID: |
| 5959 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5960 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5961 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5962 | &calldata->lsp->ls_stateid)) |
| 5963 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5964 | break; |
| 5965 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5966 | if (nfs4_async_handle_error(task, calldata->server, |
| 5967 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5968 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5969 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5970 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5971 | } |
| 5972 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5973 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5974 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5975 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5976 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5977 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5978 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5979 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5980 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5981 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5982 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5983 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5984 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5985 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5986 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5987 | &calldata->res.seq_res, |
| 5988 | task) != 0) |
| 5989 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5990 | return; |
| 5991 | out_no_action: |
| 5992 | task->tk_action = NULL; |
| 5993 | out_wait: |
| 5994 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5995 | } |
| 5996 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5997 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5998 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5999 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6000 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6001 | }; |
| 6002 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6003 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6004 | struct nfs_open_context *ctx, |
| 6005 | struct nfs4_lock_state *lsp, |
| 6006 | struct nfs_seqid *seqid) |
| 6007 | { |
| 6008 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6009 | struct rpc_message msg = { |
| 6010 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6011 | .rpc_cred = ctx->cred, |
| 6012 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6013 | struct rpc_task_setup task_setup_data = { |
| 6014 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6015 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6016 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6017 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6018 | .flags = RPC_TASK_ASYNC, |
| 6019 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6020 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6021 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6022 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6023 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6024 | /* Ensure this is an unlock - when canceling a lock, the |
| 6025 | * canceled lock is passed in, and it won't be an unlock. |
| 6026 | */ |
| 6027 | fl->fl_type = F_UNLCK; |
| 6028 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6029 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6030 | if (data == NULL) { |
| 6031 | nfs_free_seqid(seqid); |
| 6032 | return ERR_PTR(-ENOMEM); |
| 6033 | } |
| 6034 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6035 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6036 | msg.rpc_argp = &data->arg; |
| 6037 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6038 | task_setup_data.callback_data = data; |
| 6039 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6040 | } |
| 6041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6042 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6043 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6044 | struct inode *inode = state->inode; |
| 6045 | struct nfs4_state_owner *sp = state->owner; |
| 6046 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6047 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6048 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6049 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6050 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6051 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6052 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6054 | status = nfs4_set_lock_state(state, request); |
| 6055 | /* Unlock _before_ we do the RPC call */ |
| 6056 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6057 | /* Exclude nfs_delegation_claim_locks() */ |
| 6058 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6059 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6060 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6061 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6062 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6063 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6064 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6065 | } |
| 6066 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6067 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6068 | if (status != 0) |
| 6069 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6070 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6071 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6072 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6073 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6074 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6075 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6076 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6077 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6078 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6079 | 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] | 6080 | status = PTR_ERR(task); |
| 6081 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6082 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6083 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6084 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6085 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6086 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6087 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6088 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6091 | struct nfs4_lockdata { |
| 6092 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6093 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6094 | struct nfs4_lock_state *lsp; |
| 6095 | struct nfs_open_context *ctx; |
| 6096 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6097 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6098 | int rpc_status; |
| 6099 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6100 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6101 | }; |
| 6102 | |
| 6103 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6104 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6105 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6106 | { |
| 6107 | struct nfs4_lockdata *p; |
| 6108 | struct inode *inode = lsp->ls_state->inode; |
| 6109 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6110 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6111 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6112 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6113 | if (p == NULL) |
| 6114 | return NULL; |
| 6115 | |
| 6116 | p->arg.fh = NFS_FH(inode); |
| 6117 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6118 | 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] | 6119 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6120 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6121 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6122 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6123 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6124 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6125 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6126 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6127 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6128 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6129 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6130 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6131 | atomic_inc(&lsp->ls_count); |
| 6132 | p->ctx = get_nfs_open_context(ctx); |
| 6133 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6134 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6135 | out_free_seqid: |
| 6136 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6137 | out_free: |
| 6138 | kfree(p); |
| 6139 | return NULL; |
| 6140 | } |
| 6141 | |
| 6142 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6143 | { |
| 6144 | struct nfs4_lockdata *data = calldata; |
| 6145 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6146 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6147 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6148 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6149 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6150 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6151 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6152 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6153 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6154 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6155 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6156 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6157 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6158 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6159 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6160 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6161 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6162 | &data->lsp->ls_stateid); |
| 6163 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6164 | if (!nfs4_valid_open_stateid(state)) { |
| 6165 | data->rpc_status = -EBADF; |
| 6166 | task->tk_action = NULL; |
| 6167 | goto out_release_open_seqid; |
| 6168 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6169 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6170 | if (nfs4_setup_sequence(data->server, |
| 6171 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6172 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6173 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6174 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6175 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6176 | nfs_release_seqid(data->arg.open_seqid); |
| 6177 | out_release_lock_seqid: |
| 6178 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6179 | out_wait: |
| 6180 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6181 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6182 | } |
| 6183 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6184 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6185 | { |
| 6186 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6187 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6188 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6189 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6190 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6191 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6192 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6193 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6194 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6195 | switch (task->tk_status) { |
| 6196 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6197 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6198 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6199 | if (data->arg.new_lock) { |
| 6200 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6201 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6202 | rpc_restart_call_prepare(task); |
| 6203 | break; |
| 6204 | } |
| 6205 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6206 | if (data->arg.new_lock_owner != 0) { |
| 6207 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6208 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6209 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6210 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6211 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6212 | break; |
| 6213 | case -NFS4ERR_BAD_STATEID: |
| 6214 | case -NFS4ERR_OLD_STATEID: |
| 6215 | case -NFS4ERR_STALE_STATEID: |
| 6216 | case -NFS4ERR_EXPIRED: |
| 6217 | if (data->arg.new_lock_owner != 0) { |
| 6218 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6219 | &lsp->ls_state->open_stateid)) |
| 6220 | rpc_restart_call_prepare(task); |
| 6221 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6222 | &lsp->ls_stateid)) |
| 6223 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6224 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6225 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | static void nfs4_lock_release(void *calldata) |
| 6229 | { |
| 6230 | struct nfs4_lockdata *data = calldata; |
| 6231 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6232 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6233 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6234 | if (data->cancelled != 0) { |
| 6235 | struct rpc_task *task; |
| 6236 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6237 | data->arg.lock_seqid); |
| 6238 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6239 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6240 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6241 | } else |
| 6242 | nfs_free_seqid(data->arg.lock_seqid); |
| 6243 | nfs4_put_lock_state(data->lsp); |
| 6244 | put_nfs_open_context(data->ctx); |
| 6245 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6246 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6247 | } |
| 6248 | |
| 6249 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6250 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6251 | .rpc_call_done = nfs4_lock_done, |
| 6252 | .rpc_release = nfs4_lock_release, |
| 6253 | }; |
| 6254 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6255 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6256 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6257 | switch (error) { |
| 6258 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6259 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6260 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6261 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6262 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6263 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6264 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6265 | break; |
| 6266 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6267 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6268 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6269 | }; |
| 6270 | } |
| 6271 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6272 | 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] | 6273 | { |
| 6274 | struct nfs4_lockdata *data; |
| 6275 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6276 | struct rpc_message msg = { |
| 6277 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6278 | .rpc_cred = state->owner->so_cred, |
| 6279 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6280 | struct rpc_task_setup task_setup_data = { |
| 6281 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6282 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6283 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6284 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6285 | .flags = RPC_TASK_ASYNC, |
| 6286 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6287 | int ret; |
| 6288 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6289 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6290 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6291 | fl->fl_u.nfs4_fl.owner, |
| 6292 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6293 | if (data == NULL) |
| 6294 | return -ENOMEM; |
| 6295 | if (IS_SETLKW(cmd)) |
| 6296 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6297 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6298 | msg.rpc_argp = &data->arg; |
| 6299 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6300 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6301 | if (recovery_type > NFS_LOCK_NEW) { |
| 6302 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6303 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6304 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6305 | } else |
| 6306 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6307 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6308 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6309 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6310 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6311 | if (ret == 0) { |
| 6312 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6313 | if (ret) |
| 6314 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6315 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6316 | } else |
| 6317 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6318 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6319 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6320 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6321 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6325 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6326 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6327 | struct nfs4_exception exception = { |
| 6328 | .inode = state->inode, |
| 6329 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6330 | int err; |
| 6331 | |
| 6332 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6333 | /* Cache the lock if possible... */ |
| 6334 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6335 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6336 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6337 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6338 | break; |
| 6339 | nfs4_handle_exception(server, err, &exception); |
| 6340 | } while (exception.retry); |
| 6341 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6345 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6346 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6347 | struct nfs4_exception exception = { |
| 6348 | .inode = state->inode, |
| 6349 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6350 | int err; |
| 6351 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6352 | err = nfs4_set_lock_state(state, request); |
| 6353 | if (err != 0) |
| 6354 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6355 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6356 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6357 | return 0; |
| 6358 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6359 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6360 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6361 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6362 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6363 | switch (err) { |
| 6364 | default: |
| 6365 | goto out; |
| 6366 | case -NFS4ERR_GRACE: |
| 6367 | case -NFS4ERR_DELAY: |
| 6368 | nfs4_handle_exception(server, err, &exception); |
| 6369 | err = 0; |
| 6370 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6371 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6372 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6373 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6374 | } |
| 6375 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6376 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6377 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6378 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6379 | struct nfs4_lock_state *lsp; |
| 6380 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6381 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6382 | status = nfs4_set_lock_state(state, request); |
| 6383 | if (status != 0) |
| 6384 | return status; |
| 6385 | lsp = request->fl_u.nfs4_fl.owner; |
| 6386 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6387 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6388 | return 0; |
| 6389 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6390 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6391 | } |
| 6392 | #endif |
| 6393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6394 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6395 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6396 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6397 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6398 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6399 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6400 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6401 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6402 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6403 | if (status < 0) |
| 6404 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6405 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6406 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6407 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6408 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6409 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6410 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6411 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6412 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6413 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6414 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6415 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6416 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6417 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6418 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6419 | out: |
| 6420 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | return status; |
| 6422 | } |
| 6423 | |
| 6424 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6425 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6426 | struct nfs4_exception exception = { |
| 6427 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6428 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6429 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6430 | int err; |
| 6431 | |
| 6432 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6433 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6434 | if (err == -NFS4ERR_DENIED) |
| 6435 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6436 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6437 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6438 | } while (exception.retry); |
| 6439 | return err; |
| 6440 | } |
| 6441 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6442 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6443 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6444 | |
| 6445 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6446 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6447 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6448 | { |
| 6449 | int status = -ERESTARTSYS; |
| 6450 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6451 | |
| 6452 | while(!signalled()) { |
| 6453 | status = nfs4_proc_setlk(state, cmd, request); |
| 6454 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6455 | break; |
| 6456 | freezable_schedule_timeout_interruptible(timeout); |
| 6457 | timeout *= 2; |
| 6458 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6459 | status = -ERESTARTSYS; |
| 6460 | } |
| 6461 | return status; |
| 6462 | } |
| 6463 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6464 | #ifdef CONFIG_NFS_V4_1 |
| 6465 | struct nfs4_lock_waiter { |
| 6466 | struct task_struct *task; |
| 6467 | struct inode *inode; |
| 6468 | struct nfs_lowner *owner; |
| 6469 | bool notified; |
| 6470 | }; |
| 6471 | |
| 6472 | static int |
| 6473 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6474 | { |
| 6475 | int ret; |
| 6476 | struct cb_notify_lock_args *cbnl = key; |
| 6477 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6478 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6479 | *wowner = waiter->owner; |
| 6480 | |
| 6481 | /* Only wake if the callback was for the same owner */ |
| 6482 | if (lowner->clientid != wowner->clientid || |
| 6483 | lowner->id != wowner->id || |
| 6484 | lowner->s_dev != wowner->s_dev) |
| 6485 | return 0; |
| 6486 | |
| 6487 | /* Make sure it's for the right inode */ |
| 6488 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6489 | return 0; |
| 6490 | |
| 6491 | waiter->notified = true; |
| 6492 | |
| 6493 | /* override "private" so we can use default_wake_function */ |
| 6494 | wait->private = waiter->task; |
| 6495 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6496 | wait->private = waiter; |
| 6497 | return ret; |
| 6498 | } |
| 6499 | |
| 6500 | static int |
| 6501 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6502 | { |
| 6503 | int status = -ERESTARTSYS; |
| 6504 | unsigned long flags; |
| 6505 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6506 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6507 | struct nfs_client *clp = server->nfs_client; |
| 6508 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6509 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6510 | .id = lsp->ls_seqid.owner_id, |
| 6511 | .s_dev = server->s_dev }; |
| 6512 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6513 | .inode = state->inode, |
| 6514 | .owner = &owner, |
| 6515 | .notified = false }; |
| 6516 | wait_queue_t wait; |
| 6517 | |
| 6518 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6519 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6520 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6521 | |
| 6522 | init_wait(&wait); |
| 6523 | wait.private = &waiter; |
| 6524 | wait.func = nfs4_wake_lock_waiter; |
| 6525 | add_wait_queue(q, &wait); |
| 6526 | |
| 6527 | while(!signalled()) { |
| 6528 | status = nfs4_proc_setlk(state, cmd, request); |
| 6529 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6530 | break; |
| 6531 | |
| 6532 | status = -ERESTARTSYS; |
| 6533 | spin_lock_irqsave(&q->lock, flags); |
| 6534 | if (waiter.notified) { |
| 6535 | spin_unlock_irqrestore(&q->lock, flags); |
| 6536 | continue; |
| 6537 | } |
| 6538 | set_current_state(TASK_INTERRUPTIBLE); |
| 6539 | spin_unlock_irqrestore(&q->lock, flags); |
| 6540 | |
| 6541 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6542 | } |
| 6543 | |
| 6544 | finish_wait(q, &wait); |
| 6545 | return status; |
| 6546 | } |
| 6547 | #else /* !CONFIG_NFS_V4_1 */ |
| 6548 | static inline int |
| 6549 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6550 | { |
| 6551 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6552 | } |
| 6553 | #endif |
| 6554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6555 | static int |
| 6556 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6557 | { |
| 6558 | struct nfs_open_context *ctx; |
| 6559 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | int status; |
| 6561 | |
| 6562 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6563 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6564 | state = ctx->state; |
| 6565 | |
| 6566 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6567 | return -EINVAL; |
| 6568 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6569 | if (IS_GETLK(cmd)) { |
| 6570 | if (state != NULL) |
| 6571 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6572 | return 0; |
| 6573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | |
| 6575 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6576 | return -EINVAL; |
| 6577 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6578 | if (request->fl_type == F_UNLCK) { |
| 6579 | if (state != NULL) |
| 6580 | return nfs4_proc_unlck(state, cmd, request); |
| 6581 | return 0; |
| 6582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6584 | if (state == NULL) |
| 6585 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6586 | |
| 6587 | if ((request->fl_flags & FL_POSIX) && |
| 6588 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6589 | return -ENOLCK; |
| 6590 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6591 | /* |
| 6592 | * Don't rely on the VFS having checked the file open mode, |
| 6593 | * since it won't do this for flock() locks. |
| 6594 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6595 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6596 | case F_RDLCK: |
| 6597 | if (!(filp->f_mode & FMODE_READ)) |
| 6598 | return -EBADF; |
| 6599 | break; |
| 6600 | case F_WRLCK: |
| 6601 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6602 | return -EBADF; |
| 6603 | } |
| 6604 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6605 | status = nfs4_set_lock_state(state, request); |
| 6606 | if (status != 0) |
| 6607 | return status; |
| 6608 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6609 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6610 | } |
| 6611 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6612 | 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] | 6613 | { |
| 6614 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6615 | int err; |
| 6616 | |
| 6617 | err = nfs4_set_lock_state(state, fl); |
| 6618 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6619 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6620 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6621 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6622 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6623 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6624 | struct nfs_release_lockowner_data { |
| 6625 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6626 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6627 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6628 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6629 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6630 | }; |
| 6631 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6632 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6633 | { |
| 6634 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6635 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6636 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6637 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6638 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6639 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6643 | { |
| 6644 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6645 | struct nfs_server *server = data->server; |
| 6646 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6647 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6648 | |
| 6649 | switch (task->tk_status) { |
| 6650 | case 0: |
| 6651 | renew_lease(server, data->timestamp); |
| 6652 | break; |
| 6653 | case -NFS4ERR_STALE_CLIENTID: |
| 6654 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6655 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6656 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6657 | case -NFS4ERR_LEASE_MOVED: |
| 6658 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6659 | if (nfs4_async_handle_error(task, server, |
| 6660 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6661 | rpc_restart_call_prepare(task); |
| 6662 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6663 | } |
| 6664 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6665 | static void nfs4_release_lockowner_release(void *calldata) |
| 6666 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6667 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6668 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6669 | kfree(calldata); |
| 6670 | } |
| 6671 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6672 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6673 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6674 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6675 | .rpc_release = nfs4_release_lockowner_release, |
| 6676 | }; |
| 6677 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6678 | static void |
| 6679 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6680 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6681 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6682 | struct rpc_message msg = { |
| 6683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6684 | }; |
| 6685 | |
| 6686 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6687 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6688 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6689 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6690 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6691 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6692 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6693 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6694 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6695 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6696 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6697 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6698 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6699 | msg.rpc_resp = &data->res; |
| 6700 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6701 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6702 | } |
| 6703 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6704 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6705 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6706 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6707 | struct dentry *unused, struct inode *inode, |
| 6708 | const char *key, const void *buf, |
| 6709 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6710 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6711 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6712 | } |
| 6713 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6714 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6715 | struct dentry *unused, struct inode *inode, |
| 6716 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6717 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6718 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6721 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6722 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6723 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6724 | } |
| 6725 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6726 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6727 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6728 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6729 | struct dentry *unused, struct inode *inode, |
| 6730 | const char *key, const void *buf, |
| 6731 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6732 | { |
| 6733 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6734 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6735 | |
| 6736 | return -EOPNOTSUPP; |
| 6737 | } |
| 6738 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6739 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6740 | struct dentry *unused, struct inode *inode, |
| 6741 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6742 | { |
| 6743 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6744 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6745 | return -EOPNOTSUPP; |
| 6746 | } |
| 6747 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6748 | static ssize_t |
| 6749 | 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] | 6750 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6751 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6752 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6753 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6754 | len = security_inode_listsecurity(inode, list, list_len); |
| 6755 | if (list_len && len > list_len) |
| 6756 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6757 | } |
| 6758 | return len; |
| 6759 | } |
| 6760 | |
| 6761 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6762 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6763 | .get = nfs4_xattr_get_nfs4_label, |
| 6764 | .set = nfs4_xattr_set_nfs4_label, |
| 6765 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6766 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6767 | #else |
| 6768 | |
| 6769 | static ssize_t |
| 6770 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6771 | { |
| 6772 | return 0; |
| 6773 | } |
| 6774 | |
| 6775 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6776 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6777 | /* |
| 6778 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6779 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6780 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6781 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6782 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6783 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6784 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6785 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6786 | return; |
| 6787 | |
| 6788 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6789 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6790 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6791 | fattr->nlink = 2; |
| 6792 | } |
| 6793 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6794 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6795 | const struct qstr *name, |
| 6796 | struct nfs4_fs_locations *fs_locations, |
| 6797 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6798 | { |
| 6799 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6800 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6801 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6802 | }; |
| 6803 | struct nfs4_fs_locations_arg args = { |
| 6804 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6805 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6806 | .page = page, |
| 6807 | .bitmask = bitmask, |
| 6808 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6809 | struct nfs4_fs_locations_res res = { |
| 6810 | .fs_locations = fs_locations, |
| 6811 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6812 | struct rpc_message msg = { |
| 6813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6814 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6815 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6816 | }; |
| 6817 | int status; |
| 6818 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6819 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6820 | |
| 6821 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6822 | * is not supported */ |
| 6823 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6824 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6825 | else |
| 6826 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6827 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6828 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6829 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6830 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6831 | 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] | 6832 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6833 | return status; |
| 6834 | } |
| 6835 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6836 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6837 | const struct qstr *name, |
| 6838 | struct nfs4_fs_locations *fs_locations, |
| 6839 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6840 | { |
| 6841 | struct nfs4_exception exception = { }; |
| 6842 | int err; |
| 6843 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6844 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6845 | fs_locations, page); |
| 6846 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6847 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6848 | &exception); |
| 6849 | } while (exception.retry); |
| 6850 | return err; |
| 6851 | } |
| 6852 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6853 | /* |
| 6854 | * This operation also signals the server that this client is |
| 6855 | * performing migration recovery. The server can stop returning |
| 6856 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6857 | * appended to this compound to identify the client ID which is |
| 6858 | * performing recovery. |
| 6859 | */ |
| 6860 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6861 | struct nfs4_fs_locations *locations, |
| 6862 | struct page *page, struct rpc_cred *cred) |
| 6863 | { |
| 6864 | struct nfs_server *server = NFS_SERVER(inode); |
| 6865 | struct rpc_clnt *clnt = server->client; |
| 6866 | u32 bitmask[2] = { |
| 6867 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6868 | }; |
| 6869 | struct nfs4_fs_locations_arg args = { |
| 6870 | .clientid = server->nfs_client->cl_clientid, |
| 6871 | .fh = NFS_FH(inode), |
| 6872 | .page = page, |
| 6873 | .bitmask = bitmask, |
| 6874 | .migration = 1, /* skip LOOKUP */ |
| 6875 | .renew = 1, /* append RENEW */ |
| 6876 | }; |
| 6877 | struct nfs4_fs_locations_res res = { |
| 6878 | .fs_locations = locations, |
| 6879 | .migration = 1, |
| 6880 | .renew = 1, |
| 6881 | }; |
| 6882 | struct rpc_message msg = { |
| 6883 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6884 | .rpc_argp = &args, |
| 6885 | .rpc_resp = &res, |
| 6886 | .rpc_cred = cred, |
| 6887 | }; |
| 6888 | unsigned long now = jiffies; |
| 6889 | int status; |
| 6890 | |
| 6891 | nfs_fattr_init(&locations->fattr); |
| 6892 | locations->server = server; |
| 6893 | locations->nlocations = 0; |
| 6894 | |
| 6895 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6896 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6897 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6898 | &args.seq_args, &res.seq_res); |
| 6899 | if (status) |
| 6900 | return status; |
| 6901 | |
| 6902 | renew_lease(server, now); |
| 6903 | return 0; |
| 6904 | } |
| 6905 | |
| 6906 | #ifdef CONFIG_NFS_V4_1 |
| 6907 | |
| 6908 | /* |
| 6909 | * This operation also signals the server that this client is |
| 6910 | * performing migration recovery. The server can stop asserting |
| 6911 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6912 | * performing this operation is identified in the SEQUENCE |
| 6913 | * operation in this compound. |
| 6914 | * |
| 6915 | * When the client supports GETATTR(fs_locations_info), it can |
| 6916 | * be plumbed in here. |
| 6917 | */ |
| 6918 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6919 | struct nfs4_fs_locations *locations, |
| 6920 | struct page *page, struct rpc_cred *cred) |
| 6921 | { |
| 6922 | struct nfs_server *server = NFS_SERVER(inode); |
| 6923 | struct rpc_clnt *clnt = server->client; |
| 6924 | u32 bitmask[2] = { |
| 6925 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6926 | }; |
| 6927 | struct nfs4_fs_locations_arg args = { |
| 6928 | .fh = NFS_FH(inode), |
| 6929 | .page = page, |
| 6930 | .bitmask = bitmask, |
| 6931 | .migration = 1, /* skip LOOKUP */ |
| 6932 | }; |
| 6933 | struct nfs4_fs_locations_res res = { |
| 6934 | .fs_locations = locations, |
| 6935 | .migration = 1, |
| 6936 | }; |
| 6937 | struct rpc_message msg = { |
| 6938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6939 | .rpc_argp = &args, |
| 6940 | .rpc_resp = &res, |
| 6941 | .rpc_cred = cred, |
| 6942 | }; |
| 6943 | int status; |
| 6944 | |
| 6945 | nfs_fattr_init(&locations->fattr); |
| 6946 | locations->server = server; |
| 6947 | locations->nlocations = 0; |
| 6948 | |
| 6949 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6950 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6951 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6952 | &args.seq_args, &res.seq_res); |
| 6953 | if (status == NFS4_OK && |
| 6954 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6955 | status = -NFS4ERR_LEASE_MOVED; |
| 6956 | return status; |
| 6957 | } |
| 6958 | |
| 6959 | #endif /* CONFIG_NFS_V4_1 */ |
| 6960 | |
| 6961 | /** |
| 6962 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6963 | * @inode: inode on FSID that is migrating |
| 6964 | * @locations: result of query |
| 6965 | * @page: buffer |
| 6966 | * @cred: credential to use for this operation |
| 6967 | * |
| 6968 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6969 | * operation failed, or a negative errno if a local error occurred. |
| 6970 | * |
| 6971 | * On success, "locations" is filled in, but if the server has |
| 6972 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6973 | * asserted. |
| 6974 | * |
| 6975 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6976 | * from this client that require migration recovery. |
| 6977 | */ |
| 6978 | int nfs4_proc_get_locations(struct inode *inode, |
| 6979 | struct nfs4_fs_locations *locations, |
| 6980 | struct page *page, struct rpc_cred *cred) |
| 6981 | { |
| 6982 | struct nfs_server *server = NFS_SERVER(inode); |
| 6983 | struct nfs_client *clp = server->nfs_client; |
| 6984 | const struct nfs4_mig_recovery_ops *ops = |
| 6985 | clp->cl_mvops->mig_recovery_ops; |
| 6986 | struct nfs4_exception exception = { }; |
| 6987 | int status; |
| 6988 | |
| 6989 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6990 | (unsigned long long)server->fsid.major, |
| 6991 | (unsigned long long)server->fsid.minor, |
| 6992 | clp->cl_hostname); |
| 6993 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6994 | |
| 6995 | do { |
| 6996 | status = ops->get_locations(inode, locations, page, cred); |
| 6997 | if (status != -NFS4ERR_DELAY) |
| 6998 | break; |
| 6999 | nfs4_handle_exception(server, status, &exception); |
| 7000 | } while (exception.retry); |
| 7001 | return status; |
| 7002 | } |
| 7003 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7004 | /* |
| 7005 | * This operation also signals the server that this client is |
| 7006 | * performing "lease moved" recovery. The server can stop |
| 7007 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7008 | * is appended to this compound to identify the client ID which is |
| 7009 | * performing recovery. |
| 7010 | */ |
| 7011 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7012 | { |
| 7013 | struct nfs_server *server = NFS_SERVER(inode); |
| 7014 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7015 | struct rpc_clnt *clnt = server->client; |
| 7016 | struct nfs4_fsid_present_arg args = { |
| 7017 | .fh = NFS_FH(inode), |
| 7018 | .clientid = clp->cl_clientid, |
| 7019 | .renew = 1, /* append RENEW */ |
| 7020 | }; |
| 7021 | struct nfs4_fsid_present_res res = { |
| 7022 | .renew = 1, |
| 7023 | }; |
| 7024 | struct rpc_message msg = { |
| 7025 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7026 | .rpc_argp = &args, |
| 7027 | .rpc_resp = &res, |
| 7028 | .rpc_cred = cred, |
| 7029 | }; |
| 7030 | unsigned long now = jiffies; |
| 7031 | int status; |
| 7032 | |
| 7033 | res.fh = nfs_alloc_fhandle(); |
| 7034 | if (res.fh == NULL) |
| 7035 | return -ENOMEM; |
| 7036 | |
| 7037 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7038 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7039 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7040 | &args.seq_args, &res.seq_res); |
| 7041 | nfs_free_fhandle(res.fh); |
| 7042 | if (status) |
| 7043 | return status; |
| 7044 | |
| 7045 | do_renew_lease(clp, now); |
| 7046 | return 0; |
| 7047 | } |
| 7048 | |
| 7049 | #ifdef CONFIG_NFS_V4_1 |
| 7050 | |
| 7051 | /* |
| 7052 | * This operation also signals the server that this client is |
| 7053 | * performing "lease moved" recovery. The server can stop asserting |
| 7054 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7055 | * this operation is identified in the SEQUENCE operation in this |
| 7056 | * compound. |
| 7057 | */ |
| 7058 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7059 | { |
| 7060 | struct nfs_server *server = NFS_SERVER(inode); |
| 7061 | struct rpc_clnt *clnt = server->client; |
| 7062 | struct nfs4_fsid_present_arg args = { |
| 7063 | .fh = NFS_FH(inode), |
| 7064 | }; |
| 7065 | struct nfs4_fsid_present_res res = { |
| 7066 | }; |
| 7067 | struct rpc_message msg = { |
| 7068 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7069 | .rpc_argp = &args, |
| 7070 | .rpc_resp = &res, |
| 7071 | .rpc_cred = cred, |
| 7072 | }; |
| 7073 | int status; |
| 7074 | |
| 7075 | res.fh = nfs_alloc_fhandle(); |
| 7076 | if (res.fh == NULL) |
| 7077 | return -ENOMEM; |
| 7078 | |
| 7079 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7080 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7081 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7082 | &args.seq_args, &res.seq_res); |
| 7083 | nfs_free_fhandle(res.fh); |
| 7084 | if (status == NFS4_OK && |
| 7085 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7086 | status = -NFS4ERR_LEASE_MOVED; |
| 7087 | return status; |
| 7088 | } |
| 7089 | |
| 7090 | #endif /* CONFIG_NFS_V4_1 */ |
| 7091 | |
| 7092 | /** |
| 7093 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7094 | * @inode: inode on FSID to check |
| 7095 | * @cred: credential to use for this operation |
| 7096 | * |
| 7097 | * Server indicates whether the FSID is present, moved, or not |
| 7098 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7099 | * condition for this client ID. |
| 7100 | * |
| 7101 | * Returns NFS4_OK if the FSID is present on this server, |
| 7102 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7103 | * NFS4ERR code if some error occurred on the server, or a |
| 7104 | * negative errno if a local failure occurred. |
| 7105 | */ |
| 7106 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7107 | { |
| 7108 | struct nfs_server *server = NFS_SERVER(inode); |
| 7109 | struct nfs_client *clp = server->nfs_client; |
| 7110 | const struct nfs4_mig_recovery_ops *ops = |
| 7111 | clp->cl_mvops->mig_recovery_ops; |
| 7112 | struct nfs4_exception exception = { }; |
| 7113 | int status; |
| 7114 | |
| 7115 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7116 | (unsigned long long)server->fsid.major, |
| 7117 | (unsigned long long)server->fsid.minor, |
| 7118 | clp->cl_hostname); |
| 7119 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7120 | |
| 7121 | do { |
| 7122 | status = ops->fsid_present(inode, cred); |
| 7123 | if (status != -NFS4ERR_DELAY) |
| 7124 | break; |
| 7125 | nfs4_handle_exception(server, status, &exception); |
| 7126 | } while (exception.retry); |
| 7127 | return status; |
| 7128 | } |
| 7129 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7130 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7131 | * If 'use_integrity' is true and the state managment nfs_client |
| 7132 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7133 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7134 | * Considerations sections. Otherwise, just use the user cred with the |
| 7135 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7136 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7137 | 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] | 7138 | { |
| 7139 | int status; |
| 7140 | struct nfs4_secinfo_arg args = { |
| 7141 | .dir_fh = NFS_FH(dir), |
| 7142 | .name = name, |
| 7143 | }; |
| 7144 | struct nfs4_secinfo_res res = { |
| 7145 | .flavors = flavors, |
| 7146 | }; |
| 7147 | struct rpc_message msg = { |
| 7148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7149 | .rpc_argp = &args, |
| 7150 | .rpc_resp = &res, |
| 7151 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7152 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7153 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7154 | |
| 7155 | if (use_integrity) { |
| 7156 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7157 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7158 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7159 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7160 | |
| 7161 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7162 | |
| 7163 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7164 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7165 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7166 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7167 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7168 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7169 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7170 | if (cred) |
| 7171 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7172 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7173 | return status; |
| 7174 | } |
| 7175 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7176 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7177 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7178 | { |
| 7179 | struct nfs4_exception exception = { }; |
| 7180 | int err; |
| 7181 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7182 | err = -NFS4ERR_WRONGSEC; |
| 7183 | |
| 7184 | /* try to use integrity protection with machine cred */ |
| 7185 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7186 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7187 | |
| 7188 | /* |
| 7189 | * if unable to use integrity protection, or SECINFO with |
| 7190 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7191 | * disallowed by spec, but exists in deployed servers) use |
| 7192 | * the current filesystem's rpc_client and the user cred. |
| 7193 | */ |
| 7194 | if (err == -NFS4ERR_WRONGSEC) |
| 7195 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7196 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7197 | trace_nfs4_secinfo(dir, name, err); |
| 7198 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7199 | &exception); |
| 7200 | } while (exception.retry); |
| 7201 | return err; |
| 7202 | } |
| 7203 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7204 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7205 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7206 | * Check the exchange flags returned by the server for invalid flags, having |
| 7207 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7208 | * DS flags set. |
| 7209 | */ |
| 7210 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7211 | { |
| 7212 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7213 | goto out_inval; |
| 7214 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7215 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7216 | goto out_inval; |
| 7217 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7218 | goto out_inval; |
| 7219 | return NFS_OK; |
| 7220 | out_inval: |
| 7221 | return -NFS4ERR_INVAL; |
| 7222 | } |
| 7223 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7224 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7225 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7226 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7227 | { |
| 7228 | if (a->server_scope_sz == b->server_scope_sz && |
| 7229 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7230 | return true; |
| 7231 | |
| 7232 | return false; |
| 7233 | } |
| 7234 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7235 | static void |
| 7236 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7237 | { |
| 7238 | } |
| 7239 | |
| 7240 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7241 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7242 | }; |
| 7243 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7244 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7245 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7246 | * |
| 7247 | * The 4.1 client currently uses the same TCP connection for the |
| 7248 | * fore and backchannel. |
| 7249 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7250 | static |
| 7251 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7252 | struct rpc_xprt *xprt, |
| 7253 | struct nfs_client *clp, |
| 7254 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7255 | { |
| 7256 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7257 | struct nfs41_bind_conn_to_session_args args = { |
| 7258 | .client = clp, |
| 7259 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7260 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7261 | struct nfs41_bind_conn_to_session_res res; |
| 7262 | struct rpc_message msg = { |
| 7263 | .rpc_proc = |
| 7264 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7265 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7266 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7267 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7268 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7269 | struct rpc_task_setup task_setup_data = { |
| 7270 | .rpc_client = clnt, |
| 7271 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7272 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7273 | .rpc_message = &msg, |
| 7274 | .flags = RPC_TASK_TIMEOUT, |
| 7275 | }; |
| 7276 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7277 | |
| 7278 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7279 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7280 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7281 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7282 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7283 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7284 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7285 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7286 | args.dir = NFS4_CDFC4_FORE; |
| 7287 | |
| 7288 | task = rpc_run_task(&task_setup_data); |
| 7289 | if (!IS_ERR(task)) { |
| 7290 | status = task->tk_status; |
| 7291 | rpc_put_task(task); |
| 7292 | } else |
| 7293 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7294 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7295 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7296 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7297 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7298 | dprintk("NFS: %s: Session ID mismatch\n", __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 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7302 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7303 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7304 | __func__); |
| 7305 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7306 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7307 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7308 | if (res.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7309 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7310 | __func__); |
| 7311 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7312 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7313 | } |
| 7314 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7315 | out: |
| 7316 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7317 | return status; |
| 7318 | } |
| 7319 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7320 | struct rpc_bind_conn_calldata { |
| 7321 | struct nfs_client *clp; |
| 7322 | struct rpc_cred *cred; |
| 7323 | }; |
| 7324 | |
| 7325 | static int |
| 7326 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7327 | struct rpc_xprt *xprt, |
| 7328 | void *calldata) |
| 7329 | { |
| 7330 | struct rpc_bind_conn_calldata *p = calldata; |
| 7331 | |
| 7332 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7333 | } |
| 7334 | |
| 7335 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7336 | { |
| 7337 | struct rpc_bind_conn_calldata data = { |
| 7338 | .clp = clp, |
| 7339 | .cred = cred, |
| 7340 | }; |
| 7341 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7342 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7343 | } |
| 7344 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7345 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7346 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7347 | * 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] | 7348 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7349 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7350 | .how = SP4_MACH_CRED, |
| 7351 | .enforce.u.words = { |
| 7352 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7353 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7354 | 1 << (OP_CREATE_SESSION - 32) | |
| 7355 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7356 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7357 | }, |
| 7358 | .allow.u.words = { |
| 7359 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7360 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7361 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7362 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7363 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7364 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7365 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7366 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7367 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7368 | 1 << (OP_FREE_STATEID - 32) | |
| 7369 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7370 | } |
| 7371 | }; |
| 7372 | |
| 7373 | /* |
| 7374 | * Select the state protection mode for client `clp' given the server results |
| 7375 | * from exchange_id in `sp'. |
| 7376 | * |
| 7377 | * Returns 0 on success, negative errno otherwise. |
| 7378 | */ |
| 7379 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7380 | struct nfs41_state_protection *sp) |
| 7381 | { |
| 7382 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7383 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7384 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7385 | 1 << (OP_CREATE_SESSION - 32) | |
| 7386 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7387 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7388 | }; |
| 7389 | unsigned int i; |
| 7390 | |
| 7391 | if (sp->how == SP4_MACH_CRED) { |
| 7392 | /* Print state protect result */ |
| 7393 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7394 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7395 | if (test_bit(i, sp->enforce.u.longs)) |
| 7396 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7397 | if (test_bit(i, sp->allow.u.longs)) |
| 7398 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7399 | } |
| 7400 | |
| 7401 | /* make sure nothing is on enforce list that isn't supported */ |
| 7402 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7403 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7404 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7405 | return -EINVAL; |
| 7406 | } |
| 7407 | } |
| 7408 | |
| 7409 | /* |
| 7410 | * Minimal mode - state operations are allowed to use machine |
| 7411 | * credential. Note this already happens by default, so the |
| 7412 | * client doesn't have to do anything more than the negotiation. |
| 7413 | * |
| 7414 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7415 | * we're already using the machine cred for exchange_id |
| 7416 | * and will never use a different cred. |
| 7417 | */ |
| 7418 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7419 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7420 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7421 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7422 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7423 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7424 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7425 | } else { |
| 7426 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7427 | return -EINVAL; |
| 7428 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7429 | |
| 7430 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7431 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7432 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7433 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7434 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7435 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7436 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7437 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7438 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7439 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7440 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7441 | &clp->cl_sp4_flags); |
| 7442 | } |
| 7443 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7444 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7445 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7446 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7447 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7448 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7449 | |
| 7450 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7451 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7452 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7453 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7454 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7455 | |
| 7456 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7457 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7458 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7459 | } |
| 7460 | |
| 7461 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7462 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7463 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7464 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | return 0; |
| 7468 | } |
| 7469 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7470 | struct nfs41_exchange_id_data { |
| 7471 | struct nfs41_exchange_id_res res; |
| 7472 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7473 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7474 | int rpc_status; |
| 7475 | }; |
| 7476 | |
| 7477 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7478 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7479 | struct nfs41_exchange_id_data *cdata = |
| 7480 | (struct nfs41_exchange_id_data *)data; |
| 7481 | struct nfs_client *clp = cdata->args.client; |
| 7482 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7483 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7484 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7485 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7486 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7487 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7488 | |
| 7489 | if (cdata->xprt && status == 0) { |
| 7490 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7491 | cdata->xprt); |
| 7492 | goto out; |
| 7493 | } |
| 7494 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7495 | if (status == 0) |
| 7496 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7497 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7498 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7499 | clp->cl_clientid = cdata->res.clientid; |
| 7500 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7501 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7502 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7503 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7504 | &clp->cl_session->session_state); |
| 7505 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7506 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7507 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7508 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7509 | clp->cl_serverowner = cdata->res.server_owner; |
| 7510 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7511 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7512 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7513 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7514 | clp->cl_implid = cdata->res.impl_id; |
| 7515 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7516 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7517 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7518 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7519 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7520 | dprintk("%s: server_scope mismatch detected\n", |
| 7521 | __func__); |
| 7522 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7523 | kfree(clp->cl_serverscope); |
| 7524 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7525 | } |
| 7526 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7527 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7528 | clp->cl_serverscope = cdata->res.server_scope; |
| 7529 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7530 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7531 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7532 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7533 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7534 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7535 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7536 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7537 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | static void nfs4_exchange_id_release(void *data) |
| 7541 | { |
| 7542 | struct nfs41_exchange_id_data *cdata = |
| 7543 | (struct nfs41_exchange_id_data *)data; |
| 7544 | |
| 7545 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7546 | if (cdata->xprt) { |
| 7547 | xprt_put(cdata->xprt); |
| 7548 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7549 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7550 | kfree(cdata->res.impl_id); |
| 7551 | kfree(cdata->res.server_scope); |
| 7552 | kfree(cdata->res.server_owner); |
| 7553 | kfree(cdata); |
| 7554 | } |
| 7555 | |
| 7556 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7557 | .rpc_call_done = nfs4_exchange_id_done, |
| 7558 | .rpc_release = nfs4_exchange_id_release, |
| 7559 | }; |
| 7560 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7561 | /* |
| 7562 | * _nfs4_proc_exchange_id() |
| 7563 | * |
| 7564 | * Wrapper for EXCHANGE_ID operation. |
| 7565 | */ |
| 7566 | 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] | 7567 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7568 | { |
| 7569 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7570 | struct rpc_message msg = { |
| 7571 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7572 | .rpc_cred = cred, |
| 7573 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7574 | struct rpc_task_setup task_setup_data = { |
| 7575 | .rpc_client = clp->cl_rpcclient, |
| 7576 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7577 | .rpc_message = &msg, |
| 7578 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7579 | }; |
| 7580 | struct nfs41_exchange_id_data *calldata; |
| 7581 | struct rpc_task *task; |
| 7582 | int status = -EIO; |
| 7583 | |
| 7584 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7585 | goto out; |
| 7586 | |
| 7587 | status = -ENOMEM; |
| 7588 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7589 | if (!calldata) |
| 7590 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7591 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7592 | if (!xprt) |
| 7593 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7594 | |
| 7595 | status = nfs4_init_uniform_client_string(clp); |
| 7596 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7597 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7598 | |
| 7599 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7600 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7601 | clp->cl_owner_id); |
| 7602 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7603 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7604 | GFP_NOFS); |
| 7605 | status = -ENOMEM; |
| 7606 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7607 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7608 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7609 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7610 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7611 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7612 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7613 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7614 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7615 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7616 | goto out_server_scope; |
| 7617 | |
| 7618 | switch (sp4_how) { |
| 7619 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7620 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7621 | break; |
| 7622 | |
| 7623 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7624 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7625 | break; |
| 7626 | |
| 7627 | default: |
| 7628 | /* unsupported! */ |
| 7629 | WARN_ON_ONCE(1); |
| 7630 | status = -EINVAL; |
| 7631 | goto out_impl_id; |
| 7632 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7633 | if (xprt) { |
| 7634 | calldata->xprt = xprt; |
| 7635 | task_setup_data.rpc_xprt = xprt; |
| 7636 | task_setup_data.flags = |
| 7637 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7638 | calldata->args.verifier = &clp->cl_confirm; |
| 7639 | } else { |
| 7640 | calldata->args.verifier = &verifier; |
| 7641 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7642 | calldata->args.client = clp; |
| 7643 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7644 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7645 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7646 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7647 | #else |
| 7648 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7649 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7650 | #endif |
| 7651 | msg.rpc_argp = &calldata->args; |
| 7652 | msg.rpc_resp = &calldata->res; |
| 7653 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7654 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7655 | task = rpc_run_task(&task_setup_data); |
| 7656 | if (IS_ERR(task)) { |
| 7657 | status = PTR_ERR(task); |
| 7658 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7659 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7660 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7661 | if (!xprt) { |
| 7662 | status = rpc_wait_for_completion_task(task); |
| 7663 | if (!status) |
| 7664 | status = calldata->rpc_status; |
| 7665 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7666 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7667 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7668 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7669 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7670 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7671 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7672 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7673 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7674 | clp->cl_implid->date.seconds, |
| 7675 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7676 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7677 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7678 | |
| 7679 | out_impl_id: |
| 7680 | kfree(calldata->res.impl_id); |
| 7681 | out_server_scope: |
| 7682 | kfree(calldata->res.server_scope); |
| 7683 | out_server_owner: |
| 7684 | kfree(calldata->res.server_owner); |
| 7685 | out_calldata: |
| 7686 | kfree(calldata); |
| 7687 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7688 | } |
| 7689 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7690 | /* |
| 7691 | * nfs4_proc_exchange_id() |
| 7692 | * |
| 7693 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7694 | * |
| 7695 | * Since the clientid has expired, all compounds using sessions |
| 7696 | * associated with the stale clientid will be returning |
| 7697 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7698 | * be in some phase of session reset. |
| 7699 | * |
| 7700 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7701 | */ |
| 7702 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7703 | { |
| 7704 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7705 | int status; |
| 7706 | |
| 7707 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7708 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7709 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7710 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7711 | if (!status) |
| 7712 | return 0; |
| 7713 | } |
| 7714 | |
| 7715 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7716 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7717 | } |
| 7718 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7719 | /** |
| 7720 | * nfs4_test_session_trunk |
| 7721 | * |
| 7722 | * This is an add_xprt_test() test function called from |
| 7723 | * rpc_clnt_setup_test_and_add_xprt. |
| 7724 | * |
| 7725 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7726 | * and is dereferrenced in nfs4_exchange_id_release |
| 7727 | * |
| 7728 | * Upon success, add the new transport to the rpc_clnt |
| 7729 | * |
| 7730 | * @clnt: struct rpc_clnt to get new transport |
| 7731 | * @xprt: the rpc_xprt to test |
| 7732 | * @data: call data for _nfs4_proc_exchange_id. |
| 7733 | */ |
| 7734 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7735 | void *data) |
| 7736 | { |
| 7737 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7738 | u32 sp4_how; |
| 7739 | |
| 7740 | dprintk("--> %s try %s\n", __func__, |
| 7741 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7742 | |
| 7743 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7744 | |
| 7745 | /* Test connection for session trunking. Async exchange_id call */ |
| 7746 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7747 | } |
| 7748 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7749 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7750 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7751 | struct rpc_cred *cred) |
| 7752 | { |
| 7753 | struct rpc_message msg = { |
| 7754 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7755 | .rpc_argp = clp, |
| 7756 | .rpc_cred = cred, |
| 7757 | }; |
| 7758 | int status; |
| 7759 | |
| 7760 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7761 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7762 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7763 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7764 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7765 | return status; |
| 7766 | } |
| 7767 | |
| 7768 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7769 | struct rpc_cred *cred) |
| 7770 | { |
| 7771 | unsigned int loop; |
| 7772 | int ret; |
| 7773 | |
| 7774 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7775 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7776 | switch (ret) { |
| 7777 | case -NFS4ERR_DELAY: |
| 7778 | case -NFS4ERR_CLIENTID_BUSY: |
| 7779 | ssleep(1); |
| 7780 | break; |
| 7781 | default: |
| 7782 | return ret; |
| 7783 | } |
| 7784 | } |
| 7785 | return 0; |
| 7786 | } |
| 7787 | |
| 7788 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7789 | { |
| 7790 | struct rpc_cred *cred; |
| 7791 | int ret = 0; |
| 7792 | |
| 7793 | if (clp->cl_mvops->minor_version < 1) |
| 7794 | goto out; |
| 7795 | if (clp->cl_exchange_flags == 0) |
| 7796 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7797 | if (clp->cl_preserve_clid) |
| 7798 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7799 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7800 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7801 | if (cred) |
| 7802 | put_rpccred(cred); |
| 7803 | switch (ret) { |
| 7804 | case 0: |
| 7805 | case -NFS4ERR_STALE_CLIENTID: |
| 7806 | clp->cl_exchange_flags = 0; |
| 7807 | } |
| 7808 | out: |
| 7809 | return ret; |
| 7810 | } |
| 7811 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7812 | struct nfs4_get_lease_time_data { |
| 7813 | struct nfs4_get_lease_time_args *args; |
| 7814 | struct nfs4_get_lease_time_res *res; |
| 7815 | struct nfs_client *clp; |
| 7816 | }; |
| 7817 | |
| 7818 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7819 | void *calldata) |
| 7820 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7821 | struct nfs4_get_lease_time_data *data = |
| 7822 | (struct nfs4_get_lease_time_data *)calldata; |
| 7823 | |
| 7824 | dprintk("--> %s\n", __func__); |
| 7825 | /* just setup sequence, do not trigger session recovery |
| 7826 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7827 | nfs41_setup_sequence(data->clp->cl_session, |
| 7828 | &data->args->la_seq_args, |
| 7829 | &data->res->lr_seq_res, |
| 7830 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7831 | dprintk("<-- %s\n", __func__); |
| 7832 | } |
| 7833 | |
| 7834 | /* |
| 7835 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7836 | * from sequence operation or clientid errors. |
| 7837 | */ |
| 7838 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7839 | { |
| 7840 | struct nfs4_get_lease_time_data *data = |
| 7841 | (struct nfs4_get_lease_time_data *)calldata; |
| 7842 | |
| 7843 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7844 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7845 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7846 | switch (task->tk_status) { |
| 7847 | case -NFS4ERR_DELAY: |
| 7848 | case -NFS4ERR_GRACE: |
| 7849 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7850 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7851 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7852 | /* fall through */ |
| 7853 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7854 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7855 | return; |
| 7856 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7857 | dprintk("<-- %s\n", __func__); |
| 7858 | } |
| 7859 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7860 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7861 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7862 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7863 | }; |
| 7864 | |
| 7865 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7866 | { |
| 7867 | struct rpc_task *task; |
| 7868 | struct nfs4_get_lease_time_args args; |
| 7869 | struct nfs4_get_lease_time_res res = { |
| 7870 | .lr_fsinfo = fsinfo, |
| 7871 | }; |
| 7872 | struct nfs4_get_lease_time_data data = { |
| 7873 | .args = &args, |
| 7874 | .res = &res, |
| 7875 | .clp = clp, |
| 7876 | }; |
| 7877 | struct rpc_message msg = { |
| 7878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7879 | .rpc_argp = &args, |
| 7880 | .rpc_resp = &res, |
| 7881 | }; |
| 7882 | struct rpc_task_setup task_setup = { |
| 7883 | .rpc_client = clp->cl_rpcclient, |
| 7884 | .rpc_message = &msg, |
| 7885 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7886 | .callback_data = &data, |
| 7887 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7888 | }; |
| 7889 | int status; |
| 7890 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7891 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7892 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7893 | dprintk("--> %s\n", __func__); |
| 7894 | task = rpc_run_task(&task_setup); |
| 7895 | |
| 7896 | if (IS_ERR(task)) |
| 7897 | status = PTR_ERR(task); |
| 7898 | else { |
| 7899 | status = task->tk_status; |
| 7900 | rpc_put_task(task); |
| 7901 | } |
| 7902 | dprintk("<-- %s return %d\n", __func__, status); |
| 7903 | |
| 7904 | return status; |
| 7905 | } |
| 7906 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7907 | /* |
| 7908 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7909 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7910 | * use them. |
| 7911 | * |
| 7912 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7913 | * always set csa_cachethis to FALSE because the current implementation |
| 7914 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7915 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7916 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7917 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7918 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7919 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7920 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7921 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7922 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7923 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7924 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7925 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7926 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7927 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7928 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7929 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7930 | |
| 7931 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7932 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7933 | __func__, |
| 7934 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7935 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7936 | |
| 7937 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7938 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7939 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7940 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7941 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7942 | 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] | 7943 | |
| 7944 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7945 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7946 | __func__, |
| 7947 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7948 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7949 | args->bc_attrs.max_reqs); |
| 7950 | } |
| 7951 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7952 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7953 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7954 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7955 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7956 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7957 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7958 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7959 | return -EINVAL; |
| 7960 | /* |
| 7961 | * Our requested max_ops is the minimum we need; we're not |
| 7962 | * prepared to break up compounds into smaller pieces than that. |
| 7963 | * So, no point even trying to continue if the server won't |
| 7964 | * cooperate: |
| 7965 | */ |
| 7966 | if (rcvd->max_ops < sent->max_ops) |
| 7967 | return -EINVAL; |
| 7968 | if (rcvd->max_reqs == 0) |
| 7969 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7970 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7971 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7972 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7973 | } |
| 7974 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7975 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7976 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7977 | { |
| 7978 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7979 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7980 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7981 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7982 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7983 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7984 | return -EINVAL; |
| 7985 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7986 | return -EINVAL; |
| 7987 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7988 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7989 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7990 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7991 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7992 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7993 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7994 | return 0; |
| 7995 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7996 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7997 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7998 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7999 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8000 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8001 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8002 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8003 | if (ret) |
| 8004 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8005 | return nfs4_verify_back_channel_attrs(args, res); |
| 8006 | } |
| 8007 | |
| 8008 | static void nfs4_update_session(struct nfs4_session *session, |
| 8009 | struct nfs41_create_session_res *res) |
| 8010 | { |
| 8011 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8012 | /* Mark client id and session as being confirmed */ |
| 8013 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8014 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8015 | session->flags = res->flags; |
| 8016 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8017 | if (res->flags & SESSION4_BACK_CHAN) |
| 8018 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8019 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8020 | } |
| 8021 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8022 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8023 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8024 | { |
| 8025 | struct nfs4_session *session = clp->cl_session; |
| 8026 | struct nfs41_create_session_args args = { |
| 8027 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8028 | .clientid = clp->cl_clientid, |
| 8029 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8030 | .cb_program = NFS4_CALLBACK, |
| 8031 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8032 | struct nfs41_create_session_res res; |
| 8033 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8034 | struct rpc_message msg = { |
| 8035 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8036 | .rpc_argp = &args, |
| 8037 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8038 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8039 | }; |
| 8040 | int status; |
| 8041 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8042 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8043 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8044 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8045 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8046 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8047 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8048 | switch (status) { |
| 8049 | case -NFS4ERR_STALE_CLIENTID: |
| 8050 | case -NFS4ERR_DELAY: |
| 8051 | case -ETIMEDOUT: |
| 8052 | case -EACCES: |
| 8053 | case -EAGAIN: |
| 8054 | goto out; |
| 8055 | }; |
| 8056 | |
| 8057 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8058 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8059 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8060 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8061 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8062 | if (status) |
| 8063 | goto out; |
| 8064 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8065 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8066 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8067 | return status; |
| 8068 | } |
| 8069 | |
| 8070 | /* |
| 8071 | * Issues a CREATE_SESSION operation to the server. |
| 8072 | * It is the responsibility of the caller to verify the session is |
| 8073 | * expired before calling this routine. |
| 8074 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8075 | 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] | 8076 | { |
| 8077 | int status; |
| 8078 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8079 | struct nfs4_session *session = clp->cl_session; |
| 8080 | |
| 8081 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8082 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8083 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8084 | if (status) |
| 8085 | goto out; |
| 8086 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8087 | /* Init or reset the session slot tables */ |
| 8088 | status = nfs4_setup_session_slot_tables(session); |
| 8089 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8090 | if (status) |
| 8091 | goto out; |
| 8092 | |
| 8093 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8094 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8095 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8096 | out: |
| 8097 | dprintk("<-- %s\n", __func__); |
| 8098 | return status; |
| 8099 | } |
| 8100 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8101 | /* |
| 8102 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8103 | * The caller must serialize access to this routine. |
| 8104 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8105 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8106 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8107 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8108 | struct rpc_message msg = { |
| 8109 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8110 | .rpc_argp = session, |
| 8111 | .rpc_cred = cred, |
| 8112 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8113 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8114 | |
| 8115 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8116 | |
| 8117 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8118 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8119 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8120 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8121 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8122 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8123 | |
| 8124 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8125 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8126 | "Session has been destroyed regardless...\n", status); |
| 8127 | |
| 8128 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8129 | return status; |
| 8130 | } |
| 8131 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8132 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8133 | * Renew the cl_session lease. |
| 8134 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8135 | struct nfs4_sequence_data { |
| 8136 | struct nfs_client *clp; |
| 8137 | struct nfs4_sequence_args args; |
| 8138 | struct nfs4_sequence_res res; |
| 8139 | }; |
| 8140 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8141 | static void nfs41_sequence_release(void *data) |
| 8142 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8143 | struct nfs4_sequence_data *calldata = data; |
| 8144 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8145 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8146 | if (atomic_read(&clp->cl_count) > 1) |
| 8147 | nfs4_schedule_state_renewal(clp); |
| 8148 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8149 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8150 | } |
| 8151 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8152 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8153 | { |
| 8154 | switch(task->tk_status) { |
| 8155 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8156 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8157 | return -EAGAIN; |
| 8158 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8159 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8160 | } |
| 8161 | return 0; |
| 8162 | } |
| 8163 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8164 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8165 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8166 | struct nfs4_sequence_data *calldata = data; |
| 8167 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8168 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8169 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8170 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8171 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8172 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8173 | if (task->tk_status < 0) { |
| 8174 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8175 | if (atomic_read(&clp->cl_count) == 1) |
| 8176 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8177 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8178 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8179 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8180 | return; |
| 8181 | } |
| 8182 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8183 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8184 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8185 | dprintk("<-- %s\n", __func__); |
| 8186 | } |
| 8187 | |
| 8188 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8189 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8190 | struct nfs4_sequence_data *calldata = data; |
| 8191 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8192 | struct nfs4_sequence_args *args; |
| 8193 | struct nfs4_sequence_res *res; |
| 8194 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8195 | args = task->tk_msg.rpc_argp; |
| 8196 | res = task->tk_msg.rpc_resp; |
| 8197 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8198 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8202 | .rpc_call_done = nfs41_sequence_call_done, |
| 8203 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8204 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8205 | }; |
| 8206 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8207 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8208 | struct rpc_cred *cred, |
| 8209 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8210 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8211 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8212 | struct rpc_message msg = { |
| 8213 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8214 | .rpc_cred = cred, |
| 8215 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8216 | struct rpc_task_setup task_setup_data = { |
| 8217 | .rpc_client = clp->cl_rpcclient, |
| 8218 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8219 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8220 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8221 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8222 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8223 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8224 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8225 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8226 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8227 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8228 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8229 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8230 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8231 | if (is_privileged) |
| 8232 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8233 | msg.rpc_argp = &calldata->args; |
| 8234 | msg.rpc_resp = &calldata->res; |
| 8235 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8236 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8237 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8238 | return rpc_run_task(&task_setup_data); |
| 8239 | } |
| 8240 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8241 | 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] | 8242 | { |
| 8243 | struct rpc_task *task; |
| 8244 | int ret = 0; |
| 8245 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8246 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8247 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8248 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8249 | if (IS_ERR(task)) |
| 8250 | ret = PTR_ERR(task); |
| 8251 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8252 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8253 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8254 | return ret; |
| 8255 | } |
| 8256 | |
| 8257 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8258 | { |
| 8259 | struct rpc_task *task; |
| 8260 | int ret; |
| 8261 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8262 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8263 | if (IS_ERR(task)) { |
| 8264 | ret = PTR_ERR(task); |
| 8265 | goto out; |
| 8266 | } |
| 8267 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8268 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8269 | ret = task->tk_status; |
| 8270 | rpc_put_task(task); |
| 8271 | out: |
| 8272 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8273 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8274 | } |
| 8275 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8276 | struct nfs4_reclaim_complete_data { |
| 8277 | struct nfs_client *clp; |
| 8278 | struct nfs41_reclaim_complete_args arg; |
| 8279 | struct nfs41_reclaim_complete_res res; |
| 8280 | }; |
| 8281 | |
| 8282 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8283 | { |
| 8284 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8285 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8286 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8287 | &calldata->arg.seq_args, |
| 8288 | &calldata->res.seq_res, |
| 8289 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8290 | } |
| 8291 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8292 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8293 | { |
| 8294 | switch(task->tk_status) { |
| 8295 | case 0: |
| 8296 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8297 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8298 | break; |
| 8299 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8300 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8301 | /* fall through */ |
| 8302 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8303 | return -EAGAIN; |
| 8304 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8305 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8306 | } |
| 8307 | return 0; |
| 8308 | } |
| 8309 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8310 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8311 | { |
| 8312 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8313 | struct nfs_client *clp = calldata->clp; |
| 8314 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8315 | |
| 8316 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8317 | if (!nfs41_sequence_done(task, res)) |
| 8318 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8319 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8320 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8321 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8322 | rpc_restart_call_prepare(task); |
| 8323 | return; |
| 8324 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8325 | dprintk("<-- %s\n", __func__); |
| 8326 | } |
| 8327 | |
| 8328 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8329 | { |
| 8330 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8331 | |
| 8332 | kfree(calldata); |
| 8333 | } |
| 8334 | |
| 8335 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8336 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8337 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8338 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8339 | }; |
| 8340 | |
| 8341 | /* |
| 8342 | * Issue a global reclaim complete. |
| 8343 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8344 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8345 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8346 | { |
| 8347 | struct nfs4_reclaim_complete_data *calldata; |
| 8348 | struct rpc_task *task; |
| 8349 | struct rpc_message msg = { |
| 8350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8351 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8352 | }; |
| 8353 | struct rpc_task_setup task_setup_data = { |
| 8354 | .rpc_client = clp->cl_rpcclient, |
| 8355 | .rpc_message = &msg, |
| 8356 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8357 | .flags = RPC_TASK_ASYNC, |
| 8358 | }; |
| 8359 | int status = -ENOMEM; |
| 8360 | |
| 8361 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8362 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8363 | if (calldata == NULL) |
| 8364 | goto out; |
| 8365 | calldata->clp = clp; |
| 8366 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8367 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8368 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8369 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8370 | msg.rpc_argp = &calldata->arg; |
| 8371 | msg.rpc_resp = &calldata->res; |
| 8372 | task_setup_data.callback_data = calldata; |
| 8373 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8374 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8375 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8376 | goto out; |
| 8377 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8378 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8379 | if (status == 0) |
| 8380 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8381 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8382 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8383 | out: |
| 8384 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8385 | return status; |
| 8386 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8387 | |
| 8388 | static void |
| 8389 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8390 | { |
| 8391 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8392 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8393 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8394 | |
| 8395 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8396 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8397 | &lgp->res.seq_res, task); |
| 8398 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8399 | } |
| 8400 | |
| 8401 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8402 | { |
| 8403 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8404 | |
| 8405 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8406 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8407 | dprintk("<-- %s\n", __func__); |
| 8408 | } |
| 8409 | |
| 8410 | static int |
| 8411 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8412 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8413 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8414 | struct inode *inode = lgp->args.inode; |
| 8415 | struct nfs_server *server = NFS_SERVER(inode); |
| 8416 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8417 | int nfs4err = task->tk_status; |
| 8418 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8419 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8420 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8421 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8422 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8423 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8424 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8425 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8426 | |
| 8427 | /* |
| 8428 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8429 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8430 | * retry go inband. |
| 8431 | */ |
| 8432 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8433 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8434 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8435 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8436 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8437 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8438 | */ |
| 8439 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8440 | status = -EOVERFLOW; |
| 8441 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8442 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8443 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8444 | * (or clients) writing to the same RAID stripe except when |
| 8445 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8446 | * |
| 8447 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8448 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8449 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8450 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8451 | if (lgp->args.minlength == 0) { |
| 8452 | status = -EOVERFLOW; |
| 8453 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8454 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8455 | status = -EBUSY; |
| 8456 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8457 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8458 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8459 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8460 | case -NFS4ERR_DELEG_REVOKED: |
| 8461 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8462 | case -NFS4ERR_EXPIRED: |
| 8463 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8464 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8465 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8466 | lo = NFS_I(inode)->layout; |
| 8467 | /* If the open stateid was bad, then recover it. */ |
| 8468 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8469 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8470 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8471 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8472 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8473 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8474 | break; |
| 8475 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8476 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8477 | /* |
| 8478 | * Mark the bad layout state as invalid, then retry |
| 8479 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8480 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8481 | spin_unlock(&inode->i_lock); |
| 8482 | pnfs_free_lseg_list(&head); |
| 8483 | status = -EAGAIN; |
| 8484 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8485 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8486 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8487 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8488 | if (!status) { |
| 8489 | if (exception->retry) |
| 8490 | status = -EAGAIN; |
| 8491 | else |
| 8492 | status = err; |
| 8493 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8494 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8495 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8496 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8497 | } |
| 8498 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8499 | static size_t max_response_pages(struct nfs_server *server) |
| 8500 | { |
| 8501 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8502 | return nfs_page_array_len(0, max_resp_sz); |
| 8503 | } |
| 8504 | |
| 8505 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8506 | { |
| 8507 | int i; |
| 8508 | |
| 8509 | if (!pages) |
| 8510 | return; |
| 8511 | |
| 8512 | for (i = 0; i < size; i++) { |
| 8513 | if (!pages[i]) |
| 8514 | break; |
| 8515 | __free_page(pages[i]); |
| 8516 | } |
| 8517 | kfree(pages); |
| 8518 | } |
| 8519 | |
| 8520 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8521 | { |
| 8522 | struct page **pages; |
| 8523 | int i; |
| 8524 | |
| 8525 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8526 | if (!pages) { |
| 8527 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8528 | return NULL; |
| 8529 | } |
| 8530 | |
| 8531 | for (i = 0; i < size; i++) { |
| 8532 | pages[i] = alloc_page(gfp_flags); |
| 8533 | if (!pages[i]) { |
| 8534 | dprintk("%s: failed to allocate page\n", __func__); |
| 8535 | nfs4_free_pages(pages, size); |
| 8536 | return NULL; |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | return pages; |
| 8541 | } |
| 8542 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8543 | static void nfs4_layoutget_release(void *calldata) |
| 8544 | { |
| 8545 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8546 | struct inode *inode = lgp->args.inode; |
| 8547 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8548 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8549 | |
| 8550 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8551 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8552 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8553 | put_nfs_open_context(lgp->args.ctx); |
| 8554 | kfree(calldata); |
| 8555 | dprintk("<-- %s\n", __func__); |
| 8556 | } |
| 8557 | |
| 8558 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8559 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8560 | .rpc_call_done = nfs4_layoutget_done, |
| 8561 | .rpc_release = nfs4_layoutget_release, |
| 8562 | }; |
| 8563 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8564 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8565 | 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] | 8566 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8567 | struct inode *inode = lgp->args.inode; |
| 8568 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8569 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8570 | struct rpc_task *task; |
| 8571 | struct rpc_message msg = { |
| 8572 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8573 | .rpc_argp = &lgp->args, |
| 8574 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8575 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8576 | }; |
| 8577 | struct rpc_task_setup task_setup_data = { |
| 8578 | .rpc_client = server->client, |
| 8579 | .rpc_message = &msg, |
| 8580 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8581 | .callback_data = lgp, |
| 8582 | .flags = RPC_TASK_ASYNC, |
| 8583 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8584 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8585 | struct nfs4_exception exception = { |
| 8586 | .inode = inode, |
| 8587 | .timeout = *timeout, |
| 8588 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8589 | int status = 0; |
| 8590 | |
| 8591 | dprintk("--> %s\n", __func__); |
| 8592 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8593 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8594 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8595 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8596 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8597 | if (!lgp->args.layout.pages) { |
| 8598 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8599 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8600 | } |
| 8601 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8602 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8603 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8604 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8605 | 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] | 8606 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8607 | task = rpc_run_task(&task_setup_data); |
| 8608 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8609 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8610 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8611 | if (status == 0) { |
| 8612 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8613 | *timeout = exception.timeout; |
| 8614 | } |
| 8615 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8616 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8617 | &lgp->args.range, |
| 8618 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8619 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8620 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8621 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8622 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8623 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8624 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8625 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8626 | rpc_put_task(task); |
| 8627 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8628 | if (status) |
| 8629 | return ERR_PTR(status); |
| 8630 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8631 | } |
| 8632 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8633 | static void |
| 8634 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8635 | { |
| 8636 | struct nfs4_layoutreturn *lrp = calldata; |
| 8637 | |
| 8638 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8639 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8640 | &lrp->args.seq_args, |
| 8641 | &lrp->res.seq_res, |
| 8642 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8643 | } |
| 8644 | |
| 8645 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8646 | { |
| 8647 | struct nfs4_layoutreturn *lrp = calldata; |
| 8648 | struct nfs_server *server; |
| 8649 | |
| 8650 | dprintk("--> %s\n", __func__); |
| 8651 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8652 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8653 | return; |
| 8654 | |
| 8655 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8656 | switch (task->tk_status) { |
| 8657 | default: |
| 8658 | task->tk_status = 0; |
| 8659 | case 0: |
| 8660 | break; |
| 8661 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8662 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8663 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8664 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8665 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8666 | return; |
| 8667 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8668 | dprintk("<-- %s\n", __func__); |
| 8669 | } |
| 8670 | |
| 8671 | static void nfs4_layoutreturn_release(void *calldata) |
| 8672 | { |
| 8673 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8674 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8675 | |
| 8676 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8677 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8678 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8679 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8680 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8681 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8682 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8683 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8684 | kfree(calldata); |
| 8685 | dprintk("<-- %s\n", __func__); |
| 8686 | } |
| 8687 | |
| 8688 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8689 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8690 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8691 | .rpc_release = nfs4_layoutreturn_release, |
| 8692 | }; |
| 8693 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8694 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8695 | { |
| 8696 | struct rpc_task *task; |
| 8697 | struct rpc_message msg = { |
| 8698 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8699 | .rpc_argp = &lrp->args, |
| 8700 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8701 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8702 | }; |
| 8703 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8704 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8705 | .rpc_message = &msg, |
| 8706 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8707 | .callback_data = lrp, |
| 8708 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8709 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8710 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8711 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8712 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8713 | &task_setup_data.rpc_client, &msg); |
| 8714 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8715 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8716 | if (!sync) { |
| 8717 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8718 | if (!lrp->inode) { |
| 8719 | nfs4_layoutreturn_release(lrp); |
| 8720 | return -EAGAIN; |
| 8721 | } |
| 8722 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8723 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8724 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8725 | task = rpc_run_task(&task_setup_data); |
| 8726 | if (IS_ERR(task)) |
| 8727 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8728 | if (sync) |
| 8729 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8730 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8731 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8732 | rpc_put_task(task); |
| 8733 | return status; |
| 8734 | } |
| 8735 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8736 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8737 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8738 | struct pnfs_device *pdev, |
| 8739 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8740 | { |
| 8741 | struct nfs4_getdeviceinfo_args args = { |
| 8742 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8743 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8744 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8745 | }; |
| 8746 | struct nfs4_getdeviceinfo_res res = { |
| 8747 | .pdev = pdev, |
| 8748 | }; |
| 8749 | struct rpc_message msg = { |
| 8750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8751 | .rpc_argp = &args, |
| 8752 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8753 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8754 | }; |
| 8755 | int status; |
| 8756 | |
| 8757 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8758 | 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] | 8759 | if (res.notification & ~args.notify_types) |
| 8760 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8761 | if (res.notification != args.notify_types) |
| 8762 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8763 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8764 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8765 | |
| 8766 | return status; |
| 8767 | } |
| 8768 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8769 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8770 | struct pnfs_device *pdev, |
| 8771 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8772 | { |
| 8773 | struct nfs4_exception exception = { }; |
| 8774 | int err; |
| 8775 | |
| 8776 | do { |
| 8777 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8778 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8779 | &exception); |
| 8780 | } while (exception.retry); |
| 8781 | return err; |
| 8782 | } |
| 8783 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8784 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8785 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8786 | { |
| 8787 | struct nfs4_layoutcommit_data *data = calldata; |
| 8788 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8789 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8790 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8791 | nfs41_setup_sequence(session, |
| 8792 | &data->args.seq_args, |
| 8793 | &data->res.seq_res, |
| 8794 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8795 | } |
| 8796 | |
| 8797 | static void |
| 8798 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8799 | { |
| 8800 | struct nfs4_layoutcommit_data *data = calldata; |
| 8801 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8802 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8803 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8804 | return; |
| 8805 | |
| 8806 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8807 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8808 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8809 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8810 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8811 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8812 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8813 | break; |
| 8814 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8815 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8816 | rpc_restart_call_prepare(task); |
| 8817 | return; |
| 8818 | } |
| 8819 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8820 | } |
| 8821 | |
| 8822 | static void nfs4_layoutcommit_release(void *calldata) |
| 8823 | { |
| 8824 | struct nfs4_layoutcommit_data *data = calldata; |
| 8825 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8826 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8827 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8828 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8829 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8830 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8831 | kfree(data); |
| 8832 | } |
| 8833 | |
| 8834 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8835 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8836 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8837 | .rpc_release = nfs4_layoutcommit_release, |
| 8838 | }; |
| 8839 | |
| 8840 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8841 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8842 | { |
| 8843 | struct rpc_message msg = { |
| 8844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8845 | .rpc_argp = &data->args, |
| 8846 | .rpc_resp = &data->res, |
| 8847 | .rpc_cred = data->cred, |
| 8848 | }; |
| 8849 | struct rpc_task_setup task_setup_data = { |
| 8850 | .task = &data->task, |
| 8851 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8852 | .rpc_message = &msg, |
| 8853 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8854 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8855 | }; |
| 8856 | struct rpc_task *task; |
| 8857 | int status = 0; |
| 8858 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8859 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8860 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8861 | data->args.lastbytewritten, |
| 8862 | data->args.inode->i_ino); |
| 8863 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8864 | if (!sync) { |
| 8865 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8866 | if (data->inode == NULL) { |
| 8867 | nfs4_layoutcommit_release(data); |
| 8868 | return -EAGAIN; |
| 8869 | } |
| 8870 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8871 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8872 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8873 | task = rpc_run_task(&task_setup_data); |
| 8874 | if (IS_ERR(task)) |
| 8875 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8876 | if (sync) |
| 8877 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8878 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8879 | dprintk("%s: status %d\n", __func__, status); |
| 8880 | rpc_put_task(task); |
| 8881 | return status; |
| 8882 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8883 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8884 | /** |
| 8885 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8886 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8887 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8888 | static int |
| 8889 | _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] | 8890 | struct nfs_fsinfo *info, |
| 8891 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8892 | { |
| 8893 | struct nfs41_secinfo_no_name_args args = { |
| 8894 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8895 | }; |
| 8896 | struct nfs4_secinfo_res res = { |
| 8897 | .flavors = flavors, |
| 8898 | }; |
| 8899 | struct rpc_message msg = { |
| 8900 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8901 | .rpc_argp = &args, |
| 8902 | .rpc_resp = &res, |
| 8903 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8904 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8905 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8906 | int status; |
| 8907 | |
| 8908 | if (use_integrity) { |
| 8909 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8910 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8911 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8912 | } |
| 8913 | |
| 8914 | dprintk("--> %s\n", __func__); |
| 8915 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8916 | &res.seq_res, 0); |
| 8917 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8918 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8919 | if (cred) |
| 8920 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8921 | |
| 8922 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8923 | } |
| 8924 | |
| 8925 | static int |
| 8926 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8927 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8928 | { |
| 8929 | struct nfs4_exception exception = { }; |
| 8930 | int err; |
| 8931 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8932 | /* first try using integrity protection */ |
| 8933 | err = -NFS4ERR_WRONGSEC; |
| 8934 | |
| 8935 | /* try to use integrity protection with machine cred */ |
| 8936 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8937 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8938 | flavors, true); |
| 8939 | |
| 8940 | /* |
| 8941 | * if unable to use integrity protection, or SECINFO with |
| 8942 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8943 | * disallowed by spec, but exists in deployed servers) use |
| 8944 | * the current filesystem's rpc_client and the user cred. |
| 8945 | */ |
| 8946 | if (err == -NFS4ERR_WRONGSEC) |
| 8947 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8948 | flavors, false); |
| 8949 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8950 | switch (err) { |
| 8951 | case 0: |
| 8952 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8953 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8954 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8955 | default: |
| 8956 | err = nfs4_handle_exception(server, err, &exception); |
| 8957 | } |
| 8958 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8959 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8960 | return err; |
| 8961 | } |
| 8962 | |
| 8963 | static int |
| 8964 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8965 | struct nfs_fsinfo *info) |
| 8966 | { |
| 8967 | int err; |
| 8968 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8969 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8970 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8971 | struct nfs4_secinfo4 *secinfo; |
| 8972 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8973 | |
| 8974 | page = alloc_page(GFP_KERNEL); |
| 8975 | if (!page) { |
| 8976 | err = -ENOMEM; |
| 8977 | goto out; |
| 8978 | } |
| 8979 | |
| 8980 | flavors = page_address(page); |
| 8981 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8982 | |
| 8983 | /* |
| 8984 | * Fall back on "guess and check" method if |
| 8985 | * the server doesn't support SECINFO_NO_NAME |
| 8986 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8987 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8988 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8989 | goto out_freepage; |
| 8990 | } |
| 8991 | if (err) |
| 8992 | goto out_freepage; |
| 8993 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8994 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8995 | secinfo = &flavors->flavors[i]; |
| 8996 | |
| 8997 | switch (secinfo->flavor) { |
| 8998 | case RPC_AUTH_NULL: |
| 8999 | case RPC_AUTH_UNIX: |
| 9000 | case RPC_AUTH_GSS: |
| 9001 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9002 | &secinfo->flavor_info); |
| 9003 | break; |
| 9004 | default: |
| 9005 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9006 | break; |
| 9007 | } |
| 9008 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9009 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9010 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9011 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9012 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9013 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9014 | info, flavor); |
| 9015 | if (!err) |
| 9016 | break; |
| 9017 | } |
| 9018 | } |
| 9019 | |
| 9020 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9021 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9022 | |
| 9023 | out_freepage: |
| 9024 | put_page(page); |
| 9025 | if (err == -EACCES) |
| 9026 | return -EPERM; |
| 9027 | out: |
| 9028 | return err; |
| 9029 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9030 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9031 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9032 | nfs4_stateid *stateid, |
| 9033 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9034 | { |
| 9035 | int status; |
| 9036 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9037 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9038 | }; |
| 9039 | struct nfs41_test_stateid_res res; |
| 9040 | struct rpc_message msg = { |
| 9041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9042 | .rpc_argp = &args, |
| 9043 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9044 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9045 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9046 | struct rpc_clnt *rpc_client = server->client; |
| 9047 | |
| 9048 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9049 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9050 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9051 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9052 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9053 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9054 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9055 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9056 | if (status != NFS_OK) { |
| 9057 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9058 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9059 | } |
| 9060 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9061 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9062 | } |
| 9063 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9064 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9065 | int err, struct nfs4_exception *exception) |
| 9066 | { |
| 9067 | exception->retry = 0; |
| 9068 | switch(err) { |
| 9069 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9070 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9071 | nfs4_handle_exception(server, err, exception); |
| 9072 | break; |
| 9073 | case -NFS4ERR_BADSESSION: |
| 9074 | case -NFS4ERR_BADSLOT: |
| 9075 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9076 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9077 | case -NFS4ERR_DEADSESSION: |
| 9078 | nfs4_do_handle_exception(server, err, exception); |
| 9079 | } |
| 9080 | } |
| 9081 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9082 | /** |
| 9083 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9084 | * |
| 9085 | * @server: server / transport on which to perform the operation |
| 9086 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9087 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9088 | * |
| 9089 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9090 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9091 | * failed or the state ID is not currently valid. |
| 9092 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9093 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9094 | nfs4_stateid *stateid, |
| 9095 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9096 | { |
| 9097 | struct nfs4_exception exception = { }; |
| 9098 | int err; |
| 9099 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9100 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9101 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9102 | } while (exception.retry); |
| 9103 | return err; |
| 9104 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9105 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9106 | struct nfs_free_stateid_data { |
| 9107 | struct nfs_server *server; |
| 9108 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9109 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9110 | }; |
| 9111 | |
| 9112 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9113 | { |
| 9114 | struct nfs_free_stateid_data *data = calldata; |
| 9115 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 9116 | &data->args.seq_args, |
| 9117 | &data->res.seq_res, |
| 9118 | task); |
| 9119 | } |
| 9120 | |
| 9121 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9122 | { |
| 9123 | struct nfs_free_stateid_data *data = calldata; |
| 9124 | |
| 9125 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9126 | |
| 9127 | switch (task->tk_status) { |
| 9128 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9129 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9130 | rpc_restart_call_prepare(task); |
| 9131 | } |
| 9132 | } |
| 9133 | |
| 9134 | static void nfs41_free_stateid_release(void *calldata) |
| 9135 | { |
| 9136 | kfree(calldata); |
| 9137 | } |
| 9138 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9139 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9140 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9141 | .rpc_call_done = nfs41_free_stateid_done, |
| 9142 | .rpc_release = nfs41_free_stateid_release, |
| 9143 | }; |
| 9144 | |
| 9145 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9146 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9147 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9148 | bool privileged) |
| 9149 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9150 | struct rpc_message msg = { |
| 9151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9152 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9153 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9154 | struct rpc_task_setup task_setup = { |
| 9155 | .rpc_client = server->client, |
| 9156 | .rpc_message = &msg, |
| 9157 | .callback_ops = &nfs41_free_stateid_ops, |
| 9158 | .flags = RPC_TASK_ASYNC, |
| 9159 | }; |
| 9160 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9161 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9162 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9163 | &task_setup.rpc_client, &msg); |
| 9164 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9165 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9166 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9167 | if (!data) |
| 9168 | return ERR_PTR(-ENOMEM); |
| 9169 | data->server = server; |
| 9170 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9171 | |
| 9172 | task_setup.callback_data = data; |
| 9173 | |
| 9174 | msg.rpc_argp = &data->args; |
| 9175 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9176 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9177 | if (privileged) |
| 9178 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9179 | |
| 9180 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9181 | } |
| 9182 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9183 | /** |
| 9184 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9185 | * |
| 9186 | * @server: server / transport on which to perform the operation |
| 9187 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9188 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9189 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9190 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9191 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9192 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9193 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9194 | const nfs4_stateid *stateid, |
| 9195 | struct rpc_cred *cred, |
| 9196 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9197 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9198 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9199 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9200 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9201 | if (IS_ERR(task)) |
| 9202 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9203 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9204 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9205 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9206 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9207 | static void |
| 9208 | 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] | 9209 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9210 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9211 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9212 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9213 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9214 | } |
| 9215 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9216 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9217 | const nfs4_stateid *s2) |
| 9218 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9219 | if (s1->type != s2->type) |
| 9220 | return false; |
| 9221 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9222 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9223 | return false; |
| 9224 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9225 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9226 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9227 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9228 | return true; |
| 9229 | |
| 9230 | return false; |
| 9231 | } |
| 9232 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9233 | #endif /* CONFIG_NFS_V4_1 */ |
| 9234 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9235 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9236 | const nfs4_stateid *s2) |
| 9237 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9238 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9239 | } |
| 9240 | |
| 9241 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9242 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9243 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9244 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9245 | .recover_open = nfs4_open_reclaim, |
| 9246 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9247 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9248 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9249 | }; |
| 9250 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9251 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9252 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9253 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9254 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9255 | .recover_open = nfs4_open_reclaim, |
| 9256 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9257 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9258 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9259 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9260 | }; |
| 9261 | #endif /* CONFIG_NFS_V4_1 */ |
| 9262 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9263 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9264 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9265 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9266 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9267 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9268 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9269 | }; |
| 9270 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9271 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9272 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9273 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9274 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9275 | .recover_open = nfs41_open_expired, |
| 9276 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9277 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9278 | }; |
| 9279 | #endif /* CONFIG_NFS_V4_1 */ |
| 9280 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9281 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9282 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9283 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9284 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9285 | }; |
| 9286 | |
| 9287 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9288 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9289 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9290 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9291 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9292 | }; |
| 9293 | #endif |
| 9294 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9295 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9296 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9297 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9298 | }; |
| 9299 | |
| 9300 | #if defined(CONFIG_NFS_V4_1) |
| 9301 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9302 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9303 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9304 | }; |
| 9305 | #endif /* CONFIG_NFS_V4_1 */ |
| 9306 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9307 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9308 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9309 | .init_caps = NFS_CAP_READDIRPLUS |
| 9310 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9311 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9312 | .init_client = nfs40_init_client, |
| 9313 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9314 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9315 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9316 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9317 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9318 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9319 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9320 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9321 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9322 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9323 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9324 | }; |
| 9325 | |
| 9326 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9327 | static struct nfs_seqid * |
| 9328 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9329 | { |
| 9330 | return NULL; |
| 9331 | } |
| 9332 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9333 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9334 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9335 | .init_caps = NFS_CAP_READDIRPLUS |
| 9336 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9337 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9338 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9339 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9340 | .init_client = nfs41_init_client, |
| 9341 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9342 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9343 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9344 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9345 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9346 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9347 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9348 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9349 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9350 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9351 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9352 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9353 | }; |
| 9354 | #endif |
| 9355 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9356 | #if defined(CONFIG_NFS_V4_2) |
| 9357 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9358 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9359 | .init_caps = NFS_CAP_READDIRPLUS |
| 9360 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9361 | | NFS_CAP_POSIX_LOCK |
| 9362 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9363 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9364 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9365 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9366 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9367 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9368 | | NFS_CAP_LAYOUTSTATS |
| 9369 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9370 | .init_client = nfs41_init_client, |
| 9371 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9372 | .match_stateid = nfs41_match_stateid, |
| 9373 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9374 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9375 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9376 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9377 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9378 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9379 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9380 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9381 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9382 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9383 | }; |
| 9384 | #endif |
| 9385 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9386 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9387 | [0] = &nfs_v4_0_minor_ops, |
| 9388 | #if defined(CONFIG_NFS_V4_1) |
| 9389 | [1] = &nfs_v4_1_minor_ops, |
| 9390 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9391 | #if defined(CONFIG_NFS_V4_2) |
| 9392 | [2] = &nfs_v4_2_minor_ops, |
| 9393 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9394 | }; |
| 9395 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9396 | 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] | 9397 | { |
| 9398 | ssize_t error, error2; |
| 9399 | |
| 9400 | error = generic_listxattr(dentry, list, size); |
| 9401 | if (error < 0) |
| 9402 | return error; |
| 9403 | if (list) { |
| 9404 | list += error; |
| 9405 | size -= error; |
| 9406 | } |
| 9407 | |
| 9408 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9409 | if (error2 < 0) |
| 9410 | return error2; |
| 9411 | return error + error2; |
| 9412 | } |
| 9413 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9414 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9415 | .create = nfs_create, |
| 9416 | .lookup = nfs_lookup, |
| 9417 | .atomic_open = nfs_atomic_open, |
| 9418 | .link = nfs_link, |
| 9419 | .unlink = nfs_unlink, |
| 9420 | .symlink = nfs_symlink, |
| 9421 | .mkdir = nfs_mkdir, |
| 9422 | .rmdir = nfs_rmdir, |
| 9423 | .mknod = nfs_mknod, |
| 9424 | .rename = nfs_rename, |
| 9425 | .permission = nfs_permission, |
| 9426 | .getattr = nfs_getattr, |
| 9427 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9428 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9429 | }; |
| 9430 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9431 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9432 | .permission = nfs_permission, |
| 9433 | .getattr = nfs_getattr, |
| 9434 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9435 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9436 | }; |
| 9437 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9438 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9439 | .version = 4, /* protocol version */ |
| 9440 | .dentry_ops = &nfs4_dentry_operations, |
| 9441 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9442 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9443 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9444 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9445 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9446 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9447 | .getattr = nfs4_proc_getattr, |
| 9448 | .setattr = nfs4_proc_setattr, |
| 9449 | .lookup = nfs4_proc_lookup, |
| 9450 | .access = nfs4_proc_access, |
| 9451 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9452 | .create = nfs4_proc_create, |
| 9453 | .remove = nfs4_proc_remove, |
| 9454 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9455 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9456 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9457 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9458 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9459 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9460 | .link = nfs4_proc_link, |
| 9461 | .symlink = nfs4_proc_symlink, |
| 9462 | .mkdir = nfs4_proc_mkdir, |
| 9463 | .rmdir = nfs4_proc_remove, |
| 9464 | .readdir = nfs4_proc_readdir, |
| 9465 | .mknod = nfs4_proc_mknod, |
| 9466 | .statfs = nfs4_proc_statfs, |
| 9467 | .fsinfo = nfs4_proc_fsinfo, |
| 9468 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9469 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9470 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9471 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9472 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9473 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9474 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9475 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9476 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9477 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9478 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9480 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9481 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9482 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9483 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9484 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9485 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9486 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9487 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9488 | .create_server = nfs4_create_server, |
| 9489 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9490 | }; |
| 9491 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9492 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9493 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9494 | .list = nfs4_xattr_list_nfs4_acl, |
| 9495 | .get = nfs4_xattr_get_nfs4_acl, |
| 9496 | .set = nfs4_xattr_set_nfs4_acl, |
| 9497 | }; |
| 9498 | |
| 9499 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9500 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9501 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9502 | &nfs4_xattr_nfs4_label_handler, |
| 9503 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9504 | NULL |
| 9505 | }; |
| 9506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9507 | /* |
| 9508 | * Local variables: |
| 9509 | * c-basic-offset: 8 |
| 9510 | * End: |
| 9511 | */ |