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> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | 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] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | 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] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 100 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 101 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 102 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 103 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 229 | | FATTR4_WORD0_CHANGE |
| 230 | | FATTR4_WORD0_FILEID, |
| 231 | }; |
| 232 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 233 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | FATTR4_WORD0_FILES_AVAIL |
| 235 | | FATTR4_WORD0_FILES_FREE |
| 236 | | FATTR4_WORD0_FILES_TOTAL, |
| 237 | FATTR4_WORD1_SPACE_AVAIL |
| 238 | | FATTR4_WORD1_SPACE_FREE |
| 239 | | FATTR4_WORD1_SPACE_TOTAL |
| 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | FATTR4_WORD0_MAXLINK |
| 244 | | FATTR4_WORD0_MAXNAME, |
| 245 | 0 |
| 246 | }; |
| 247 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 248 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | | FATTR4_WORD0_MAXREAD |
| 250 | | FATTR4_WORD0_MAXWRITE |
| 251 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 252 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 253 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 254 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 255 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | FATTR4_WORD0_TYPE |
| 260 | | FATTR4_WORD0_CHANGE |
| 261 | | FATTR4_WORD0_SIZE |
| 262 | | FATTR4_WORD0_FSID |
| 263 | | FATTR4_WORD0_FILEID |
| 264 | | FATTR4_WORD0_FS_LOCATIONS, |
| 265 | FATTR4_WORD1_MODE |
| 266 | | FATTR4_WORD1_NUMLINKS |
| 267 | | FATTR4_WORD1_OWNER |
| 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | readdir->cookie = 0; |
| 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 290 | if (cookie == 2) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * NFSv4 servers do not return entries for '.' and '..' |
| 295 | * Therefore, we fake these entries here. We let '.' |
| 296 | * have cookie 0 and '..' have cookie 1. Note that |
| 297 | * when talking to the server, we always send cookie 0 |
| 298 | * instead of 1 or 2. |
| 299 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (cookie == 0) { |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_one; /* cookie, second word */ |
| 306 | *p++ = xdr_one; /* entry len */ |
| 307 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
| 322 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 323 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 324 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | readdir->pgbase = (char *)p - (char *)start; |
| 327 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 331 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 332 | nfs4_stateid *stateid, |
| 333 | struct rpc_cred *cred) |
| 334 | { |
| 335 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 336 | |
| 337 | ops->test_and_free_expired(server, stateid, cred); |
| 338 | } |
| 339 | |
| 340 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 341 | nfs4_stateid *stateid, |
| 342 | struct rpc_cred *cred) |
| 343 | { |
| 344 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 345 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 346 | } |
| 347 | |
| 348 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 349 | const nfs4_stateid *stateid, |
| 350 | struct rpc_cred *cred) |
| 351 | { |
| 352 | nfs4_stateid tmp; |
| 353 | |
| 354 | nfs4_stateid_copy(&tmp, stateid); |
| 355 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 356 | } |
| 357 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 358 | static long nfs4_update_delay(long *timeout) |
| 359 | { |
| 360 | long ret; |
| 361 | if (!timeout) |
| 362 | return NFS4_POLL_RETRY_MAX; |
| 363 | if (*timeout <= 0) |
| 364 | *timeout = NFS4_POLL_RETRY_MIN; |
| 365 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 366 | *timeout = NFS4_POLL_RETRY_MAX; |
| 367 | ret = *timeout; |
| 368 | *timeout <<= 1; |
| 369 | return ret; |
| 370 | } |
| 371 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 373 | { |
| 374 | int res = 0; |
| 375 | |
| 376 | might_sleep(); |
| 377 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 378 | freezable_schedule_timeout_killable_unsafe( |
| 379 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | if (fatal_signal_pending(current)) |
| 381 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | return res; |
| 383 | } |
| 384 | |
| 385 | /* This is the error handling routine for processes that are allowed |
| 386 | * to sleep. |
| 387 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 388 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 389 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 390 | { |
| 391 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 392 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 393 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 394 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 395 | int ret = errorcode; |
| 396 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 397 | exception->delay = 0; |
| 398 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 400 | |
| 401 | if (stateid == NULL && state != NULL) |
| 402 | stateid = &state->stateid; |
| 403 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | switch(errorcode) { |
| 405 | case 0: |
| 406 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 407 | case -NFS4ERR_DELEG_REVOKED: |
| 408 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 409 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 410 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 411 | if (inode != NULL && stateid != NULL) { |
| 412 | nfs_inode_find_state_and_recover(inode, |
| 413 | stateid); |
| 414 | goto wait_on_recovery; |
| 415 | } |
| 416 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 417 | if (inode) { |
| 418 | int err; |
| 419 | |
| 420 | err = nfs_async_inode_return_delegation(inode, |
| 421 | stateid); |
| 422 | if (err == 0) |
| 423 | goto wait_on_recovery; |
| 424 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 425 | exception->retry = 1; |
| 426 | break; |
| 427 | } |
| 428 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 429 | if (state == NULL) |
| 430 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 431 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 432 | if (ret < 0) |
| 433 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 434 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 436 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 437 | nfs4_schedule_lease_recovery(clp); |
| 438 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 439 | case -NFS4ERR_MOVED: |
| 440 | ret = nfs4_schedule_migration_recovery(server); |
| 441 | if (ret < 0) |
| 442 | break; |
| 443 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 444 | case -NFS4ERR_LEASE_MOVED: |
| 445 | nfs4_schedule_lease_moved_recovery(clp); |
| 446 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 447 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 448 | case -NFS4ERR_BADSESSION: |
| 449 | case -NFS4ERR_BADSLOT: |
| 450 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 451 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 452 | case -NFS4ERR_DEADSESSION: |
| 453 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 454 | case -NFS4ERR_SEQ_MISORDERED: |
| 455 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 456 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 457 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 458 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 459 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 460 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 461 | if (exception->timeout > HZ) { |
| 462 | /* We have retried a decent amount, time to |
| 463 | * fail |
| 464 | */ |
| 465 | ret = -EBUSY; |
| 466 | break; |
| 467 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 468 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 469 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 470 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 471 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 472 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 473 | exception->delay = 1; |
| 474 | return 0; |
| 475 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 476 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 477 | case -NFS4ERR_OLD_STATEID: |
| 478 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 479 | break; |
| 480 | case -NFS4ERR_BADOWNER: |
| 481 | /* The following works around a Linux server bug! */ |
| 482 | case -NFS4ERR_BADNAME: |
| 483 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 484 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 485 | exception->retry = 1; |
| 486 | printk(KERN_WARNING "NFS: v4 server %s " |
| 487 | "does not accept raw " |
| 488 | "uid/gids. " |
| 489 | "Reenabling the idmapper.\n", |
| 490 | server->nfs_client->cl_hostname); |
| 491 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 492 | } |
| 493 | /* We failed to handle the error */ |
| 494 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 495 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 496 | exception->recovering = 1; |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /* This is the error handling routine for processes that are allowed |
| 501 | * to sleep. |
| 502 | */ |
| 503 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 504 | { |
| 505 | struct nfs_client *clp = server->nfs_client; |
| 506 | int ret; |
| 507 | |
| 508 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 509 | if (exception->delay) { |
| 510 | ret = nfs4_delay(server->client, &exception->timeout); |
| 511 | goto out_retry; |
| 512 | } |
| 513 | if (exception->recovering) { |
| 514 | ret = nfs4_wait_clnt_recover(clp); |
| 515 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 516 | return -EIO; |
| 517 | goto out_retry; |
| 518 | } |
| 519 | return ret; |
| 520 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 521 | if (ret == 0) |
| 522 | exception->retry = 1; |
| 523 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 526 | static int |
| 527 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 528 | int errorcode, struct nfs4_exception *exception) |
| 529 | { |
| 530 | struct nfs_client *clp = server->nfs_client; |
| 531 | int ret; |
| 532 | |
| 533 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 534 | if (exception->delay) { |
| 535 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 536 | goto out_retry; |
| 537 | } |
| 538 | if (exception->recovering) { |
| 539 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 540 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 541 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 542 | goto out_retry; |
| 543 | } |
| 544 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 545 | ret = -EIO; |
| 546 | return ret; |
| 547 | out_retry: |
| 548 | if (ret == 0) |
| 549 | exception->retry = 1; |
| 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | static int |
| 554 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 555 | struct nfs4_state *state, long *timeout) |
| 556 | { |
| 557 | struct nfs4_exception exception = { |
| 558 | .state = state, |
| 559 | }; |
| 560 | |
| 561 | if (task->tk_status >= 0) |
| 562 | return 0; |
| 563 | if (timeout) |
| 564 | exception.timeout = *timeout; |
| 565 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 566 | task->tk_status, |
| 567 | &exception); |
| 568 | if (exception.delay && timeout) |
| 569 | *timeout = exception.timeout; |
| 570 | if (exception.retry) |
| 571 | return -EAGAIN; |
| 572 | return 0; |
| 573 | } |
| 574 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 575 | /* |
| 576 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 577 | * or 'false' otherwise. |
| 578 | */ |
| 579 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 580 | { |
| 581 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 582 | |
| 583 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 584 | flavor == RPC_AUTH_GSS_KRB5P) |
| 585 | return true; |
| 586 | |
| 587 | return false; |
| 588 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 589 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 590 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | spin_lock(&clp->cl_lock); |
| 593 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 594 | clp->cl_last_renewal = timestamp; |
| 595 | spin_unlock(&clp->cl_lock); |
| 596 | } |
| 597 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 598 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 599 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 600 | struct nfs_client *clp = server->nfs_client; |
| 601 | |
| 602 | if (!nfs4_has_session(clp)) |
| 603 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 606 | struct nfs4_call_sync_data { |
| 607 | const struct nfs_server *seq_server; |
| 608 | struct nfs4_sequence_args *seq_args; |
| 609 | struct nfs4_sequence_res *seq_res; |
| 610 | }; |
| 611 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 612 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 613 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 614 | { |
| 615 | args->sa_slot = NULL; |
| 616 | args->sa_cache_this = cache_reply; |
| 617 | args->sa_privileged = 0; |
| 618 | |
| 619 | res->sr_slot = NULL; |
| 620 | } |
| 621 | |
| 622 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 623 | { |
| 624 | args->sa_privileged = 1; |
| 625 | } |
| 626 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 627 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 628 | struct nfs4_sequence_args *args, |
| 629 | struct nfs4_sequence_res *res, |
| 630 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 631 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 632 | struct nfs4_slot *slot; |
| 633 | |
| 634 | /* slot already allocated? */ |
| 635 | if (res->sr_slot != NULL) |
| 636 | goto out_start; |
| 637 | |
| 638 | spin_lock(&tbl->slot_tbl_lock); |
| 639 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 640 | goto out_sleep; |
| 641 | |
| 642 | slot = nfs4_alloc_slot(tbl); |
| 643 | if (IS_ERR(slot)) { |
| 644 | if (slot == ERR_PTR(-ENOMEM)) |
| 645 | task->tk_timeout = HZ >> 2; |
| 646 | goto out_sleep; |
| 647 | } |
| 648 | spin_unlock(&tbl->slot_tbl_lock); |
| 649 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 650 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 651 | args->sa_slot = slot; |
| 652 | res->sr_slot = slot; |
| 653 | |
| 654 | out_start: |
| 655 | rpc_call_start(task); |
| 656 | return 0; |
| 657 | |
| 658 | out_sleep: |
| 659 | if (args->sa_privileged) |
| 660 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 661 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 662 | else |
| 663 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 664 | spin_unlock(&tbl->slot_tbl_lock); |
| 665 | return -EAGAIN; |
| 666 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 667 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 668 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 669 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 670 | { |
| 671 | struct nfs4_slot *slot = res->sr_slot; |
| 672 | struct nfs4_slot_table *tbl; |
| 673 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 674 | tbl = slot->table; |
| 675 | spin_lock(&tbl->slot_tbl_lock); |
| 676 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 677 | nfs4_free_slot(tbl, slot); |
| 678 | spin_unlock(&tbl->slot_tbl_lock); |
| 679 | |
| 680 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static int nfs40_sequence_done(struct rpc_task *task, |
| 684 | struct nfs4_sequence_res *res) |
| 685 | { |
| 686 | if (res->sr_slot != NULL) |
| 687 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 688 | return 1; |
| 689 | } |
| 690 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 691 | #if defined(CONFIG_NFS_V4_1) |
| 692 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 693 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 694 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 695 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 696 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 697 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 698 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 699 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 700 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 701 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 702 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 703 | /* Bump the slot sequence number */ |
| 704 | if (slot->seq_done) |
| 705 | slot->seq_nr++; |
| 706 | slot->seq_done = 0; |
| 707 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 708 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 709 | /* Be nice to the server: try to ensure that the last transmitted |
| 710 | * value for highest_user_slotid <= target_highest_slotid |
| 711 | */ |
| 712 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 713 | send_new_highest_used_slotid = true; |
| 714 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 715 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 716 | send_new_highest_used_slotid = false; |
| 717 | goto out_unlock; |
| 718 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 719 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 720 | |
| 721 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 722 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 723 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 724 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 725 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 726 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 727 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 728 | if (waitqueue_active(&tbl->slot_waitq)) |
| 729 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 732 | static int nfs41_sequence_process(struct rpc_task *task, |
| 733 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 734 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 735 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 736 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 737 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 738 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 739 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 740 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 741 | if (slot == NULL) |
| 742 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 743 | /* don't increment the sequence number if the task wasn't sent */ |
| 744 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 745 | goto out; |
| 746 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 747 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 748 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 749 | if (slot->interrupted) { |
| 750 | slot->interrupted = 0; |
| 751 | interrupted = true; |
| 752 | } |
| 753 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 754 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 755 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 756 | switch (res->sr_status) { |
| 757 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 758 | /* If previous op on slot was interrupted and we reused |
| 759 | * the seq# and got a reply from the cache, then retry |
| 760 | */ |
| 761 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 762 | ++slot->seq_nr; |
| 763 | goto retry_nowait; |
| 764 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 765 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 766 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 767 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 768 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 769 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 770 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 771 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 772 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 773 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 774 | case 1: |
| 775 | /* |
| 776 | * sr_status remains 1 if an RPC level error occurred. |
| 777 | * The server may or may not have processed the sequence |
| 778 | * operation.. |
| 779 | * Mark the slot as having hosted an interrupted RPC call. |
| 780 | */ |
| 781 | slot->interrupted = 1; |
| 782 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 783 | case -NFS4ERR_DELAY: |
| 784 | /* The server detected a resend of the RPC call and |
| 785 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 786 | * of RFC5661. |
| 787 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 788 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 789 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 790 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 791 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 792 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 793 | case -NFS4ERR_BADSLOT: |
| 794 | /* |
| 795 | * The slot id we used was probably retired. Try again |
| 796 | * using a different slot id. |
| 797 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 798 | goto retry_nowait; |
| 799 | case -NFS4ERR_SEQ_MISORDERED: |
| 800 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 801 | * Was the last operation on this sequence interrupted? |
| 802 | * If so, retry after bumping the sequence number. |
| 803 | */ |
| 804 | if (interrupted) { |
| 805 | ++slot->seq_nr; |
| 806 | goto retry_nowait; |
| 807 | } |
| 808 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 809 | * Could this slot have been previously retired? |
| 810 | * If so, then the server may be expecting seq_nr = 1! |
| 811 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 812 | if (slot->seq_nr != 1) { |
| 813 | slot->seq_nr = 1; |
| 814 | goto retry_nowait; |
| 815 | } |
| 816 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 817 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 818 | ++slot->seq_nr; |
| 819 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 820 | default: |
| 821 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 822 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 823 | } |
| 824 | out: |
| 825 | /* The session may be reset by one of the error handlers. */ |
| 826 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 827 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 828 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 829 | retry_nowait: |
| 830 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 831 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 832 | task->tk_status = 0; |
| 833 | ret = 0; |
| 834 | } |
| 835 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 836 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 837 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | goto out; |
| 839 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 840 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 841 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 842 | |
| 843 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 844 | { |
| 845 | if (!nfs41_sequence_process(task, res)) |
| 846 | return 0; |
| 847 | if (res->sr_slot != NULL) |
| 848 | nfs41_sequence_free_slot(res); |
| 849 | return 1; |
| 850 | |
| 851 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 852 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 853 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 854 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 855 | { |
| 856 | if (res->sr_slot == NULL) |
| 857 | return 1; |
| 858 | if (res->sr_slot->table->session != NULL) |
| 859 | return nfs41_sequence_process(task, res); |
| 860 | return nfs40_sequence_done(task, res); |
| 861 | } |
| 862 | |
| 863 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 864 | { |
| 865 | if (res->sr_slot != NULL) { |
| 866 | if (res->sr_slot->table->session != NULL) |
| 867 | nfs41_sequence_free_slot(res); |
| 868 | else |
| 869 | nfs40_sequence_free_slot(res); |
| 870 | } |
| 871 | } |
| 872 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 873 | 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] | 874 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 875 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 876 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 877 | if (!res->sr_slot->table->session) |
| 878 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 879 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 880 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 881 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 882 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 883 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 884 | struct nfs4_sequence_args *args, |
| 885 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 886 | struct rpc_task *task) |
| 887 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 888 | struct nfs4_slot *slot; |
| 889 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 890 | |
| 891 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 892 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 893 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 894 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 895 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 896 | tbl = &session->fc_slot_table; |
| 897 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 898 | task->tk_timeout = 0; |
| 899 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 900 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 901 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 902 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 903 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 904 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 905 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 906 | } |
| 907 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 908 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 909 | if (IS_ERR(slot)) { |
| 910 | /* If out of memory, try again in 1/4 second */ |
| 911 | if (slot == ERR_PTR(-ENOMEM)) |
| 912 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 913 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 914 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 915 | } |
| 916 | spin_unlock(&tbl->slot_tbl_lock); |
| 917 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 918 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 919 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 920 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 921 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 922 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 923 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 924 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 925 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 926 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 927 | /* |
| 928 | * sr_status is only set in decode_sequence, and so will remain |
| 929 | * set to 1 if an rpc level failure occurs. |
| 930 | */ |
| 931 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 932 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 933 | out_success: |
| 934 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 935 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 936 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 937 | /* Privileged tasks are queued with top priority */ |
| 938 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 939 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 940 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 941 | else |
| 942 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 943 | spin_unlock(&tbl->slot_tbl_lock); |
| 944 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 945 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 946 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 948 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 949 | struct nfs4_sequence_args *args, |
| 950 | struct nfs4_sequence_res *res, |
| 951 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 952 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 953 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 954 | int ret = 0; |
| 955 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 956 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 957 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 958 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 959 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 960 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 961 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 962 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 963 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 964 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 965 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 966 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 967 | return ret; |
| 968 | } |
| 969 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 970 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 971 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 972 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 973 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 974 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 975 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 976 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 977 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 978 | } |
| 979 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 980 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 981 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 982 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 983 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 984 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 987 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 988 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 989 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 990 | }; |
| 991 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 992 | #else /* !CONFIG_NFS_V4_1 */ |
| 993 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 994 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 995 | struct nfs4_sequence_args *args, |
| 996 | struct nfs4_sequence_res *res, |
| 997 | struct rpc_task *task) |
| 998 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 999 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 1000 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 1001 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1002 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1003 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1004 | { |
| 1005 | return nfs40_sequence_done(task, res); |
| 1006 | } |
| 1007 | |
| 1008 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1009 | { |
| 1010 | if (res->sr_slot != NULL) |
| 1011 | nfs40_sequence_free_slot(res); |
| 1012 | } |
| 1013 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1014 | int nfs4_sequence_done(struct rpc_task *task, |
| 1015 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1016 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1017 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1018 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1019 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1020 | |
| 1021 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1022 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1023 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1024 | { |
| 1025 | struct nfs4_call_sync_data *data = calldata; |
| 1026 | nfs4_setup_sequence(data->seq_server, |
| 1027 | data->seq_args, data->seq_res, task); |
| 1028 | } |
| 1029 | |
| 1030 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1031 | { |
| 1032 | struct nfs4_call_sync_data *data = calldata; |
| 1033 | nfs4_sequence_done(task, data->seq_res); |
| 1034 | } |
| 1035 | |
| 1036 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1037 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1038 | .rpc_call_done = nfs40_call_sync_done, |
| 1039 | }; |
| 1040 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1041 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1042 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1043 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1044 | struct nfs4_sequence_args *args, |
| 1045 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1046 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1047 | int ret; |
| 1048 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1049 | struct nfs_client *clp = server->nfs_client; |
| 1050 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1051 | .seq_server = server, |
| 1052 | .seq_args = args, |
| 1053 | .seq_res = res, |
| 1054 | }; |
| 1055 | struct rpc_task_setup task_setup = { |
| 1056 | .rpc_client = clnt, |
| 1057 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1058 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1059 | .callback_data = &data |
| 1060 | }; |
| 1061 | |
| 1062 | task = rpc_run_task(&task_setup); |
| 1063 | if (IS_ERR(task)) |
| 1064 | ret = PTR_ERR(task); |
| 1065 | else { |
| 1066 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1067 | rpc_put_task(task); |
| 1068 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1069 | return ret; |
| 1070 | } |
| 1071 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1072 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1073 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1074 | struct rpc_message *msg, |
| 1075 | struct nfs4_sequence_args *args, |
| 1076 | struct nfs4_sequence_res *res, |
| 1077 | int cache_reply) |
| 1078 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1079 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1080 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1081 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1084 | { |
| 1085 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1086 | |
| 1087 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1088 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1089 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1091 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1092 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1093 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | spin_unlock(&dir->i_lock); |
| 1095 | } |
| 1096 | |
| 1097 | struct nfs4_opendata { |
| 1098 | struct kref kref; |
| 1099 | struct nfs_openargs o_arg; |
| 1100 | struct nfs_openres o_res; |
| 1101 | struct nfs_open_confirmargs c_arg; |
| 1102 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1103 | struct nfs4_string owner_name; |
| 1104 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1105 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1107 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1109 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | struct nfs4_state_owner *owner; |
| 1111 | struct nfs4_state *state; |
| 1112 | struct iattr attrs; |
| 1113 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1114 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1115 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1116 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1117 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | int cancelled; |
| 1119 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1120 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1121 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1122 | int err, struct nfs4_exception *exception) |
| 1123 | { |
| 1124 | if (err != -EINVAL) |
| 1125 | return false; |
| 1126 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1127 | return false; |
| 1128 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1129 | exception->retry = 1; |
| 1130 | return true; |
| 1131 | } |
| 1132 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1133 | static u32 |
| 1134 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1135 | fmode_t fmode, int openflags) |
| 1136 | { |
| 1137 | u32 res = 0; |
| 1138 | |
| 1139 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1140 | case FMODE_READ: |
| 1141 | res = NFS4_SHARE_ACCESS_READ; |
| 1142 | break; |
| 1143 | case FMODE_WRITE: |
| 1144 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1145 | break; |
| 1146 | case FMODE_READ|FMODE_WRITE: |
| 1147 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1148 | } |
| 1149 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1150 | goto out; |
| 1151 | /* Want no delegation if we're using O_DIRECT */ |
| 1152 | if (openflags & O_DIRECT) |
| 1153 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1154 | out: |
| 1155 | return res; |
| 1156 | } |
| 1157 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1158 | static enum open_claim_type4 |
| 1159 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1160 | enum open_claim_type4 claim) |
| 1161 | { |
| 1162 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1163 | return claim; |
| 1164 | switch (claim) { |
| 1165 | default: |
| 1166 | return claim; |
| 1167 | case NFS4_OPEN_CLAIM_FH: |
| 1168 | return NFS4_OPEN_CLAIM_NULL; |
| 1169 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1170 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1171 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1172 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1173 | } |
| 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
| 1176 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | { |
| 1178 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1179 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1180 | p->o_res.seqid = p->o_arg.seqid; |
| 1181 | p->c_res.seqid = p->c_arg.seqid; |
| 1182 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1183 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1184 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1185 | 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] | 1186 | } |
| 1187 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1188 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1190 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1191 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1192 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1193 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1194 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1195 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1196 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1197 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1198 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1199 | struct nfs4_opendata *p; |
| 1200 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1201 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1202 | if (p == NULL) |
| 1203 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1204 | |
| 1205 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1206 | if (IS_ERR(p->f_label)) |
| 1207 | goto err_free_p; |
| 1208 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1209 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1210 | if (IS_ERR(p->a_label)) |
| 1211 | goto err_free_f; |
| 1212 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1213 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1214 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1215 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1216 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1217 | nfs_sb_active(dentry->d_sb); |
| 1218 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1219 | p->dir = parent; |
| 1220 | p->owner = sp; |
| 1221 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1222 | p->o_arg.open_flags = flags; |
| 1223 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1224 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1225 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1226 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1227 | * will return permission denied for all bits until close */ |
| 1228 | if (!(flags & O_EXCL)) { |
| 1229 | /* ask server to check for all possible rights as results |
| 1230 | * are cached */ |
| 1231 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1232 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1233 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1234 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1235 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1236 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1237 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1238 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1239 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1240 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1241 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1242 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1243 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1244 | case NFS4_OPEN_CLAIM_NULL: |
| 1245 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1246 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1247 | p->o_arg.fh = NFS_FH(dir); |
| 1248 | break; |
| 1249 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1250 | case NFS4_OPEN_CLAIM_FH: |
| 1251 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1252 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1253 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1254 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1255 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1256 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1257 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | p->o_arg.u.attrs = &p->attrs; |
| 1259 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1260 | |
| 1261 | verf[0] = jiffies; |
| 1262 | verf[1] = current->pid; |
| 1263 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1264 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1265 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1266 | p->c_arg.fh = &p->o_res.fh; |
| 1267 | p->c_arg.stateid = &p->o_res.stateid; |
| 1268 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1269 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1270 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1272 | |
| 1273 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1274 | nfs4_label_free(p->a_label); |
| 1275 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1276 | nfs4_label_free(p->f_label); |
| 1277 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | kfree(p); |
| 1279 | err: |
| 1280 | dput(parent); |
| 1281 | return NULL; |
| 1282 | } |
| 1283 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1284 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1285 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1286 | struct nfs4_opendata *p = container_of(kref, |
| 1287 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1288 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1289 | |
| 1290 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1291 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1292 | if (p->state != NULL) |
| 1293 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1294 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1295 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1296 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1297 | nfs4_label_free(p->f_label); |
| 1298 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1299 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1300 | dput(p->dentry); |
| 1301 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1302 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1303 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1304 | kfree(p); |
| 1305 | } |
| 1306 | |
| 1307 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1308 | { |
| 1309 | if (p != NULL) |
| 1310 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1313 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1314 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1315 | int ret; |
| 1316 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1317 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1318 | return ret; |
| 1319 | } |
| 1320 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1321 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1322 | fmode_t fmode) |
| 1323 | { |
| 1324 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1325 | case FMODE_READ|FMODE_WRITE: |
| 1326 | return state->n_rdwr != 0; |
| 1327 | case FMODE_WRITE: |
| 1328 | return state->n_wronly != 0; |
| 1329 | case FMODE_READ: |
| 1330 | return state->n_rdonly != 0; |
| 1331 | } |
| 1332 | WARN_ON_ONCE(1); |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1336 | 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] | 1337 | { |
| 1338 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1339 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1340 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1341 | goto out; |
| 1342 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1343 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1344 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1345 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1346 | break; |
| 1347 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1348 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1349 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1350 | break; |
| 1351 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1352 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1353 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1354 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1356 | return ret; |
| 1357 | } |
| 1358 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1359 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1360 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1361 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1362 | if (delegation == NULL) |
| 1363 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1364 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1365 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1366 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1367 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1368 | switch (claim) { |
| 1369 | case NFS4_OPEN_CLAIM_NULL: |
| 1370 | case NFS4_OPEN_CLAIM_FH: |
| 1371 | break; |
| 1372 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1373 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1374 | break; |
| 1375 | default: |
| 1376 | return 0; |
| 1377 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1378 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
| 1381 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1382 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1383 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1384 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1385 | case FMODE_WRITE: |
| 1386 | state->n_wronly++; |
| 1387 | break; |
| 1388 | case FMODE_READ: |
| 1389 | state->n_rdonly++; |
| 1390 | break; |
| 1391 | case FMODE_READ|FMODE_WRITE: |
| 1392 | state->n_rdwr++; |
| 1393 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1394 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1397 | #ifdef CONFIG_NFS_V4_1 |
| 1398 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1399 | { |
| 1400 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1401 | return true; |
| 1402 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1403 | return true; |
| 1404 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1405 | return true; |
| 1406 | return false; |
| 1407 | } |
| 1408 | #endif /* CONFIG_NFS_V4_1 */ |
| 1409 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1410 | 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] | 1411 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1412 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1413 | bool need_recover = false; |
| 1414 | |
| 1415 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1416 | need_recover = true; |
| 1417 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1418 | need_recover = true; |
| 1419 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1420 | need_recover = true; |
| 1421 | if (need_recover) |
| 1422 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1423 | } |
| 1424 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1425 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1426 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1427 | { |
| 1428 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1429 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1430 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1431 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1432 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1433 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1434 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1435 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1436 | return true; |
| 1437 | return false; |
| 1438 | } |
| 1439 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1440 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1441 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1442 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1443 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1444 | if (state->n_wronly) |
| 1445 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1446 | if (state->n_rdonly) |
| 1447 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1448 | if (state->n_rdwr) |
| 1449 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1450 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1451 | } |
| 1452 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1453 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1454 | nfs4_stateid *stateid, fmode_t fmode) |
| 1455 | { |
| 1456 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1457 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1458 | case FMODE_WRITE: |
| 1459 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1460 | break; |
| 1461 | case FMODE_READ: |
| 1462 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1463 | break; |
| 1464 | case 0: |
| 1465 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1466 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1467 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1468 | } |
| 1469 | if (stateid == NULL) |
| 1470 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1471 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1472 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1473 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1474 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1475 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1476 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1477 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1478 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1479 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1480 | } |
| 1481 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1482 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1483 | nfs4_stateid *arg_stateid, |
| 1484 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1485 | { |
| 1486 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1487 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1488 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1489 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1490 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1491 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1492 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1493 | } |
| 1494 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1495 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1496 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1497 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1498 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1499 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1500 | case FMODE_READ: |
| 1501 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1502 | break; |
| 1503 | case FMODE_WRITE: |
| 1504 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1505 | break; |
| 1506 | case FMODE_READ|FMODE_WRITE: |
| 1507 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1508 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1509 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1510 | return; |
| 1511 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1512 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1513 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1514 | } |
| 1515 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1516 | static void __update_open_stateid(struct nfs4_state *state, |
| 1517 | const nfs4_stateid *open_stateid, |
| 1518 | const nfs4_stateid *deleg_stateid, |
| 1519 | fmode_t fmode, |
| 1520 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1522 | /* |
| 1523 | * Protect the call to nfs4_state_set_mode_locked and |
| 1524 | * serialise the stateid update |
| 1525 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1526 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1527 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1528 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1529 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1530 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1531 | } |
| 1532 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1533 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1534 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1535 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1536 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1539 | static int update_open_stateid(struct nfs4_state *state, |
| 1540 | const nfs4_stateid *open_stateid, |
| 1541 | const nfs4_stateid *delegation, |
| 1542 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1543 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1544 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1545 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1546 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1547 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1548 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1549 | int ret = 0; |
| 1550 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1551 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1552 | |
| 1553 | rcu_read_lock(); |
| 1554 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1555 | if (deleg_cur == NULL) |
| 1556 | goto no_delegation; |
| 1557 | |
| 1558 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1559 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1560 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1561 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1562 | goto no_delegation_unlock; |
| 1563 | |
| 1564 | if (delegation == NULL) |
| 1565 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1566 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1567 | goto no_delegation_unlock; |
| 1568 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1569 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1570 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1571 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1572 | ret = 1; |
| 1573 | no_delegation_unlock: |
| 1574 | spin_unlock(&deleg_cur->lock); |
| 1575 | no_delegation: |
| 1576 | rcu_read_unlock(); |
| 1577 | |
| 1578 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1579 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1580 | ret = 1; |
| 1581 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1582 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1583 | nfs4_schedule_state_manager(clp); |
| 1584 | if (freeme.type != 0) |
| 1585 | nfs4_test_and_free_stateid(server, &freeme, |
| 1586 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1587 | |
| 1588 | return ret; |
| 1589 | } |
| 1590 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1591 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1592 | const nfs4_stateid *stateid) |
| 1593 | { |
| 1594 | struct nfs4_state *state = lsp->ls_state; |
| 1595 | bool ret = false; |
| 1596 | |
| 1597 | spin_lock(&state->state_lock); |
| 1598 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1599 | goto out_noupdate; |
| 1600 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1601 | goto out_noupdate; |
| 1602 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1603 | ret = true; |
| 1604 | out_noupdate: |
| 1605 | spin_unlock(&state->state_lock); |
| 1606 | return ret; |
| 1607 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1608 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1609 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1610 | { |
| 1611 | struct nfs_delegation *delegation; |
| 1612 | |
| 1613 | rcu_read_lock(); |
| 1614 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1615 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1616 | rcu_read_unlock(); |
| 1617 | return; |
| 1618 | } |
| 1619 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1620 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1621 | } |
| 1622 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1623 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1624 | { |
| 1625 | struct nfs4_state *state = opendata->state; |
| 1626 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1627 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1628 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1629 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1630 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1631 | nfs4_stateid stateid; |
| 1632 | int ret = -EAGAIN; |
| 1633 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1634 | for (;;) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1635 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1636 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1637 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1638 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1639 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1640 | } |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1641 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1642 | rcu_read_lock(); |
| 1643 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1644 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1645 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1646 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1647 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1648 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1649 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1650 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1651 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1652 | if (!opendata->is_recover) { |
| 1653 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1654 | if (ret != 0) |
| 1655 | goto out; |
| 1656 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1657 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1658 | |
| 1659 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1660 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1661 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1662 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1663 | out: |
| 1664 | return ERR_PTR(ret); |
| 1665 | out_return_state: |
| 1666 | atomic_inc(&state->count); |
| 1667 | return state; |
| 1668 | } |
| 1669 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1670 | static void |
| 1671 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1672 | { |
| 1673 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1674 | struct nfs_delegation *delegation; |
| 1675 | int delegation_flags = 0; |
| 1676 | |
| 1677 | rcu_read_lock(); |
| 1678 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1679 | if (delegation) |
| 1680 | delegation_flags = delegation->flags; |
| 1681 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1682 | switch (data->o_arg.claim) { |
| 1683 | default: |
| 1684 | break; |
| 1685 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1686 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1687 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1688 | "returning a delegation for " |
| 1689 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1690 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1691 | return; |
| 1692 | } |
| 1693 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1694 | nfs_inode_set_delegation(state->inode, |
| 1695 | data->owner->so_cred, |
| 1696 | &data->o_res); |
| 1697 | else |
| 1698 | nfs_inode_reclaim_delegation(state->inode, |
| 1699 | data->owner->so_cred, |
| 1700 | &data->o_res); |
| 1701 | } |
| 1702 | |
| 1703 | /* |
| 1704 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1705 | * and update the nfs4_state. |
| 1706 | */ |
| 1707 | static struct nfs4_state * |
| 1708 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1709 | { |
| 1710 | struct inode *inode = data->state->inode; |
| 1711 | struct nfs4_state *state = data->state; |
| 1712 | int ret; |
| 1713 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1714 | if (!data->rpc_done) { |
| 1715 | if (data->rpc_status) { |
| 1716 | ret = data->rpc_status; |
| 1717 | goto err; |
| 1718 | } |
| 1719 | /* cached opens have already been processed */ |
| 1720 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1723 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1724 | if (ret) |
| 1725 | goto err; |
| 1726 | |
| 1727 | if (data->o_res.delegation_type != 0) |
| 1728 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1729 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1730 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1731 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1732 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1733 | |
| 1734 | return state; |
| 1735 | err: |
| 1736 | return ERR_PTR(ret); |
| 1737 | |
| 1738 | } |
| 1739 | |
| 1740 | static struct nfs4_state * |
| 1741 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1742 | { |
| 1743 | struct inode *inode; |
| 1744 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1745 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1746 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1747 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1748 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1749 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1750 | goto out; |
| 1751 | } |
| 1752 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1753 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1754 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1755 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1756 | 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] | 1757 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1758 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1759 | goto err; |
| 1760 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1761 | state = nfs4_get_open_state(inode, data->owner); |
| 1762 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1763 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1764 | if (data->o_res.delegation_type != 0) |
| 1765 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1766 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1767 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1768 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1769 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1770 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1771 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1772 | err_put_inode: |
| 1773 | iput(inode); |
| 1774 | err: |
| 1775 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1776 | } |
| 1777 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1778 | static struct nfs4_state * |
| 1779 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1780 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1781 | struct nfs4_state *ret; |
| 1782 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1783 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1784 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1785 | else |
| 1786 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1787 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1788 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1789 | } |
| 1790 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1791 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1792 | { |
| 1793 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1794 | struct nfs_open_context *ctx; |
| 1795 | |
| 1796 | spin_lock(&state->inode->i_lock); |
| 1797 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1798 | if (ctx->state != state) |
| 1799 | continue; |
| 1800 | get_nfs_open_context(ctx); |
| 1801 | spin_unlock(&state->inode->i_lock); |
| 1802 | return ctx; |
| 1803 | } |
| 1804 | spin_unlock(&state->inode->i_lock); |
| 1805 | return ERR_PTR(-ENOENT); |
| 1806 | } |
| 1807 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1808 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1809 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1810 | { |
| 1811 | struct nfs4_opendata *opendata; |
| 1812 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1813 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1814 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1815 | if (opendata == NULL) |
| 1816 | return ERR_PTR(-ENOMEM); |
| 1817 | opendata->state = state; |
| 1818 | atomic_inc(&state->count); |
| 1819 | return opendata; |
| 1820 | } |
| 1821 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1822 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1823 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1825 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1826 | int ret; |
| 1827 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1828 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1829 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1830 | opendata->o_arg.open_flags = 0; |
| 1831 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1832 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1833 | NFS_SB(opendata->dentry->d_sb), |
| 1834 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1835 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1836 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1837 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1838 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1839 | if (ret != 0) |
| 1840 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1841 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1842 | if (IS_ERR(newstate)) |
| 1843 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1844 | if (newstate != opendata->state) |
| 1845 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1846 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1847 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1851 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1852 | int ret; |
| 1853 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1854 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1855 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1856 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1857 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1858 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1859 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1860 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1861 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1862 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1863 | if (ret != 0) |
| 1864 | return ret; |
| 1865 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1866 | if (ret != 0) |
| 1867 | return ret; |
| 1868 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1869 | if (ret != 0) |
| 1870 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1871 | /* |
| 1872 | * We may have performed cached opens for all three recoveries. |
| 1873 | * Check if we need to update the current stateid. |
| 1874 | */ |
| 1875 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1876 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1877 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1878 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1879 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1880 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1881 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1882 | return 0; |
| 1883 | } |
| 1884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | /* |
| 1886 | * OPEN_RECLAIM: |
| 1887 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1889 | 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] | 1890 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1891 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1892 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1893 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | int status; |
| 1895 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1896 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1897 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1898 | if (IS_ERR(opendata)) |
| 1899 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1900 | rcu_read_lock(); |
| 1901 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1902 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1903 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1904 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1905 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1906 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1907 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | return status; |
| 1909 | } |
| 1910 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1911 | 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] | 1912 | { |
| 1913 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1914 | struct nfs4_exception exception = { }; |
| 1915 | int err; |
| 1916 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1917 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1918 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1919 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1920 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1921 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1922 | break; |
| 1923 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } while (exception.retry); |
| 1925 | return err; |
| 1926 | } |
| 1927 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1928 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1929 | { |
| 1930 | struct nfs_open_context *ctx; |
| 1931 | int ret; |
| 1932 | |
| 1933 | ctx = nfs4_state_find_open_context(state); |
| 1934 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1935 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1936 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1937 | put_nfs_open_context(ctx); |
| 1938 | return ret; |
| 1939 | } |
| 1940 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1941 | 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] | 1942 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1943 | switch (err) { |
| 1944 | default: |
| 1945 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1946 | "%d.\n", __func__, err); |
| 1947 | case 0: |
| 1948 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1949 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1950 | case -ESTALE: |
| 1951 | break; |
| 1952 | case -NFS4ERR_BADSESSION: |
| 1953 | case -NFS4ERR_BADSLOT: |
| 1954 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1955 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1956 | case -NFS4ERR_DEADSESSION: |
| 1957 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1958 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1959 | return -EAGAIN; |
| 1960 | case -NFS4ERR_STALE_CLIENTID: |
| 1961 | case -NFS4ERR_STALE_STATEID: |
| 1962 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1963 | /* Don't recall a delegation if it was lost */ |
| 1964 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1965 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1966 | case -NFS4ERR_MOVED: |
| 1967 | nfs4_schedule_migration_recovery(server); |
| 1968 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1969 | case -NFS4ERR_LEASE_MOVED: |
| 1970 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1971 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1972 | case -NFS4ERR_DELEG_REVOKED: |
| 1973 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1974 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1975 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1976 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1977 | nfs_inode_find_state_and_recover(state->inode, |
| 1978 | stateid); |
| 1979 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1980 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1981 | case -NFS4ERR_DELAY: |
| 1982 | case -NFS4ERR_GRACE: |
| 1983 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1984 | ssleep(1); |
| 1985 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1986 | case -ENOMEM: |
| 1987 | case -NFS4ERR_DENIED: |
| 1988 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1989 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1990 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | return err; |
| 1992 | } |
| 1993 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1994 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1995 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1996 | fmode_t type) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1997 | { |
| 1998 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1999 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2000 | int err = 0; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2001 | |
| 2002 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2003 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2004 | if (IS_ERR(opendata)) |
| 2005 | return PTR_ERR(opendata); |
| 2006 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2007 | write_seqlock(&state->seqlock); |
| 2008 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2009 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2010 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2011 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2012 | case FMODE_READ|FMODE_WRITE: |
| 2013 | case FMODE_WRITE: |
| 2014 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2015 | if (err) |
| 2016 | break; |
| 2017 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2018 | if (err) |
| 2019 | break; |
| 2020 | case FMODE_READ: |
| 2021 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2022 | } |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2023 | nfs4_opendata_put(opendata); |
| 2024 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2025 | } |
| 2026 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2027 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2028 | { |
| 2029 | struct nfs4_opendata *data = calldata; |
| 2030 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2031 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2032 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2033 | } |
| 2034 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2035 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2036 | { |
| 2037 | struct nfs4_opendata *data = calldata; |
| 2038 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2039 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2040 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2041 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2042 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2043 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2044 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2045 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2046 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2047 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | static void nfs4_open_confirm_release(void *calldata) |
| 2051 | { |
| 2052 | struct nfs4_opendata *data = calldata; |
| 2053 | struct nfs4_state *state = NULL; |
| 2054 | |
| 2055 | /* If this request hasn't been cancelled, do nothing */ |
| 2056 | if (data->cancelled == 0) |
| 2057 | goto out_free; |
| 2058 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2059 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2060 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2061 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2062 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2063 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2064 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2065 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2069 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2070 | .rpc_call_done = nfs4_open_confirm_done, |
| 2071 | .rpc_release = nfs4_open_confirm_release, |
| 2072 | }; |
| 2073 | |
| 2074 | /* |
| 2075 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2076 | */ |
| 2077 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2078 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2079 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2080 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2081 | struct rpc_message msg = { |
| 2082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2083 | .rpc_argp = &data->c_arg, |
| 2084 | .rpc_resp = &data->c_res, |
| 2085 | .rpc_cred = data->owner->so_cred, |
| 2086 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2087 | struct rpc_task_setup task_setup_data = { |
| 2088 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2089 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2090 | .callback_ops = &nfs4_open_confirm_ops, |
| 2091 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2092 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2093 | .flags = RPC_TASK_ASYNC, |
| 2094 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | int status; |
| 2096 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2097 | 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] | 2098 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2099 | data->rpc_done = 0; |
| 2100 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2101 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2102 | if (data->is_recover) |
| 2103 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2104 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2105 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2106 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2107 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2108 | if (status != 0) { |
| 2109 | data->cancelled = 1; |
| 2110 | smp_wmb(); |
| 2111 | } else |
| 2112 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2113 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | return status; |
| 2115 | } |
| 2116 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2117 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2119 | struct nfs4_opendata *data = calldata; |
| 2120 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2121 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2122 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2123 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2124 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2125 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2126 | /* |
| 2127 | * Check if we still need to send an OPEN call, or if we can use |
| 2128 | * a delegation instead. |
| 2129 | */ |
| 2130 | if (data->state != NULL) { |
| 2131 | struct nfs_delegation *delegation; |
| 2132 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2133 | 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] | 2134 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2135 | rcu_read_lock(); |
| 2136 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2137 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2138 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2139 | rcu_read_unlock(); |
| 2140 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2141 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2142 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2143 | switch (claim) { |
| 2144 | default: |
| 2145 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2146 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2147 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2148 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2149 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2150 | case NFS4_OPEN_CLAIM_FH: |
| 2151 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2152 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2153 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2154 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2155 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2156 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2157 | &data->o_res.seq_res, |
| 2158 | task) != 0) |
| 2159 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2160 | |
| 2161 | /* Set the create mode (note dependency on the session type) */ |
| 2162 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2163 | if (data->o_arg.open_flags & O_EXCL) { |
| 2164 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2165 | if (nfs4_has_persistent_session(clp)) |
| 2166 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2167 | else if (clp->cl_mvops->minor_version > 0) |
| 2168 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2169 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2170 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2171 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2172 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2173 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2174 | out_no_action: |
| 2175 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2176 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2177 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2178 | } |
| 2179 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2180 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2181 | { |
| 2182 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2184 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2185 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2186 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2187 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2188 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2189 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2190 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2191 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2192 | case S_IFREG: |
| 2193 | break; |
| 2194 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2195 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2196 | break; |
| 2197 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2198 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2199 | break; |
| 2200 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2201 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2202 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2203 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2204 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2205 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2206 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2207 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2208 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2209 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2210 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2211 | static void nfs4_open_release(void *calldata) |
| 2212 | { |
| 2213 | struct nfs4_opendata *data = calldata; |
| 2214 | struct nfs4_state *state = NULL; |
| 2215 | |
| 2216 | /* If this request hasn't been cancelled, do nothing */ |
| 2217 | if (data->cancelled == 0) |
| 2218 | goto out_free; |
| 2219 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2220 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2221 | goto out_free; |
| 2222 | /* In case we need an open_confirm, no cleanup! */ |
| 2223 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2224 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2225 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2226 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2227 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2228 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2229 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2233 | .rpc_call_prepare = nfs4_open_prepare, |
| 2234 | .rpc_call_done = nfs4_open_done, |
| 2235 | .rpc_release = nfs4_open_release, |
| 2236 | }; |
| 2237 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2238 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2239 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2240 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2241 | struct nfs_server *server = NFS_SERVER(dir); |
| 2242 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2243 | struct nfs_openres *o_res = &data->o_res; |
| 2244 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2245 | struct rpc_message msg = { |
| 2246 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2247 | .rpc_argp = o_arg, |
| 2248 | .rpc_resp = o_res, |
| 2249 | .rpc_cred = data->owner->so_cred, |
| 2250 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2251 | struct rpc_task_setup task_setup_data = { |
| 2252 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2253 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2254 | .callback_ops = &nfs4_open_ops, |
| 2255 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2256 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2257 | .flags = RPC_TASK_ASYNC, |
| 2258 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2259 | int status; |
| 2260 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2261 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2262 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2263 | data->rpc_done = 0; |
| 2264 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2265 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2266 | data->is_recover = 0; |
| 2267 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2268 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2269 | data->is_recover = 1; |
| 2270 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2271 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2272 | if (IS_ERR(task)) |
| 2273 | return PTR_ERR(task); |
| 2274 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2275 | if (status != 0) { |
| 2276 | data->cancelled = 1; |
| 2277 | smp_wmb(); |
| 2278 | } else |
| 2279 | status = data->rpc_status; |
| 2280 | rpc_put_task(task); |
| 2281 | |
| 2282 | return status; |
| 2283 | } |
| 2284 | |
| 2285 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2286 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2287 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2288 | struct nfs_openres *o_res = &data->o_res; |
| 2289 | int status; |
| 2290 | |
| 2291 | status = nfs4_run_open_task(data, 1); |
| 2292 | if (status != 0 || !data->rpc_done) |
| 2293 | return status; |
| 2294 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2295 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2296 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2297 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2298 | status = _nfs4_proc_open_confirm(data); |
| 2299 | if (status != 0) |
| 2300 | return status; |
| 2301 | } |
| 2302 | |
| 2303 | return status; |
| 2304 | } |
| 2305 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2306 | /* |
| 2307 | * Additional permission checks in order to distinguish between an |
| 2308 | * open for read, and an open for execute. This works around the |
| 2309 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2310 | * the same. |
| 2311 | * Note that in the non-execute case, we want to turn off permission |
| 2312 | * checking if we just created a new file (POSIX open() semantics). |
| 2313 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2314 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2315 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2316 | struct nfs4_state *state, fmode_t fmode, |
| 2317 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2318 | { |
| 2319 | struct nfs_access_entry cache; |
| 2320 | u32 mask; |
| 2321 | |
| 2322 | /* access call failed or for some reason the server doesn't |
| 2323 | * support any access modes -- defer access call until later */ |
| 2324 | if (opendata->o_res.access_supported == 0) |
| 2325 | return 0; |
| 2326 | |
| 2327 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2328 | /* |
| 2329 | * Use openflags to check for exec, because fmode won't |
| 2330 | * always have FMODE_EXEC set when file open for exec. |
| 2331 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2332 | if (openflags & __FMODE_EXEC) { |
| 2333 | /* ONLY check for exec rights */ |
| 2334 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2335 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2336 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2337 | |
| 2338 | cache.cred = cred; |
| 2339 | cache.jiffies = jiffies; |
| 2340 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2341 | nfs_access_add_cache(state->inode, &cache); |
| 2342 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2343 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2344 | return 0; |
| 2345 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2346 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2347 | } |
| 2348 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2349 | /* |
| 2350 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2351 | */ |
| 2352 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2353 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2354 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2355 | struct nfs_server *server = NFS_SERVER(dir); |
| 2356 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2357 | struct nfs_openres *o_res = &data->o_res; |
| 2358 | int status; |
| 2359 | |
| 2360 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2361 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2362 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2363 | if (status != 0) { |
| 2364 | if (status == -NFS4ERR_BADNAME && |
| 2365 | !(o_arg->open_flags & O_CREAT)) |
| 2366 | return -ENOENT; |
| 2367 | return status; |
| 2368 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2369 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2370 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2371 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2372 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2373 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2374 | if (o_arg->open_flags & O_EXCL) |
| 2375 | data->file_created = 1; |
| 2376 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2377 | data->file_created = 1; |
| 2378 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2379 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2380 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2382 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2384 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | } |
Trond Myklebust | 88ac6b7 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2386 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2387 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2388 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 88ac6b7 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2389 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2390 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2393 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2394 | { |
| 2395 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2396 | } |
| 2397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | /* |
| 2399 | * OPEN_EXPIRED: |
| 2400 | * reclaim state on the server after a network partition. |
| 2401 | * Assumes caller holds the appropriate lock |
| 2402 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2403 | 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] | 2404 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2405 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2406 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2408 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2409 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2410 | if (IS_ERR(opendata)) |
| 2411 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2412 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2413 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2414 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2415 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2416 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2419 | 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] | 2420 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2421 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2422 | struct nfs4_exception exception = { }; |
| 2423 | int err; |
| 2424 | |
| 2425 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2426 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2427 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2428 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2429 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2430 | switch (err) { |
| 2431 | default: |
| 2432 | goto out; |
| 2433 | case -NFS4ERR_GRACE: |
| 2434 | case -NFS4ERR_DELAY: |
| 2435 | nfs4_handle_exception(server, err, &exception); |
| 2436 | err = 0; |
| 2437 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2438 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2439 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2440 | return err; |
| 2441 | } |
| 2442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2444 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2446 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2448 | ctx = nfs4_state_find_open_context(state); |
| 2449 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2450 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2451 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2452 | put_nfs_open_context(ctx); |
| 2453 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2456 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2457 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2458 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2459 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2460 | write_seqlock(&state->seqlock); |
| 2461 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2462 | write_sequnlock(&state->seqlock); |
| 2463 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2464 | } |
| 2465 | |
| 2466 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2467 | { |
| 2468 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2469 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2473 | { |
| 2474 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2475 | nfs40_clear_delegation_stateid(state); |
| 2476 | return nfs4_open_expired(sp, state); |
| 2477 | } |
| 2478 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2479 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2480 | nfs4_stateid *stateid, |
| 2481 | struct rpc_cred *cred) |
| 2482 | { |
| 2483 | return -NFS4ERR_BAD_STATEID; |
| 2484 | } |
| 2485 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2486 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2487 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2488 | nfs4_stateid *stateid, |
| 2489 | struct rpc_cred *cred) |
| 2490 | { |
| 2491 | int status; |
| 2492 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2493 | switch (stateid->type) { |
| 2494 | default: |
| 2495 | break; |
| 2496 | case NFS4_INVALID_STATEID_TYPE: |
| 2497 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2498 | return -NFS4ERR_BAD_STATEID; |
| 2499 | case NFS4_REVOKED_STATEID_TYPE: |
| 2500 | goto out_free; |
| 2501 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2502 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2503 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2504 | switch (status) { |
| 2505 | case -NFS4ERR_EXPIRED: |
| 2506 | case -NFS4ERR_ADMIN_REVOKED: |
| 2507 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2508 | break; |
| 2509 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2510 | return status; |
| 2511 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2512 | out_free: |
| 2513 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2514 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2515 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2518 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2519 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2520 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2521 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2522 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2523 | struct rpc_cred *cred; |
| 2524 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2525 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2526 | /* Get the delegation credential for use by test/free_stateid */ |
| 2527 | rcu_read_lock(); |
| 2528 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2529 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2530 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2531 | return; |
| 2532 | } |
| 2533 | |
| 2534 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 461bbb9 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2535 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2536 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2537 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2538 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2539 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2540 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2541 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2542 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2543 | cred = get_rpccred(delegation->cred); |
| 2544 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2545 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2546 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2547 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2548 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2549 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2550 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2554 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2555 | * |
| 2556 | * @state: NFSv4 state for an inode |
| 2557 | * |
| 2558 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2559 | * Otherwise a negative NFS4ERR value is returned. |
| 2560 | */ |
| 2561 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2562 | { |
| 2563 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2564 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2565 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2566 | |
| 2567 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2568 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2569 | |
| 2570 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2571 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2572 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2573 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2574 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2575 | atomic_inc(&lsp->ls_count); |
| 2576 | spin_unlock(&state->state_lock); |
| 2577 | |
| 2578 | nfs4_put_lock_state(prev); |
| 2579 | prev = lsp; |
| 2580 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2581 | status = nfs41_test_and_free_expired_stateid(server, |
| 2582 | &lsp->ls_stateid, |
| 2583 | cred); |
| 2584 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2585 | if (status == -NFS4ERR_EXPIRED || |
| 2586 | status == -NFS4ERR_BAD_STATEID) { |
| 2587 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2588 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2589 | if (!recover_lost_locks) |
| 2590 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2591 | } else if (status != NFS_OK) { |
| 2592 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2593 | nfs4_put_lock_state(prev); |
| 2594 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2595 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2596 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2597 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2598 | } |
| 2599 | spin_unlock(&state->state_lock); |
| 2600 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2601 | out: |
| 2602 | return ret; |
| 2603 | } |
| 2604 | |
| 2605 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2606 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2607 | * |
| 2608 | * @state: NFSv4 state for an inode |
| 2609 | * |
| 2610 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2611 | * Otherwise a negative NFS4ERR value is returned. |
| 2612 | */ |
| 2613 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2614 | { |
| 2615 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2616 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2617 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2618 | int status; |
| 2619 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2620 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2621 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2622 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2623 | return NFS_OK; |
| 2624 | return -NFS4ERR_OPENMODE; |
| 2625 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2626 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2627 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2628 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2629 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2630 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2631 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2632 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2633 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2634 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2635 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2636 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2637 | if (status != NFS_OK) |
| 2638 | return status; |
| 2639 | if (nfs_open_stateid_recover_openmode(state)) |
| 2640 | return -NFS4ERR_OPENMODE; |
| 2641 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2645 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2646 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2647 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2648 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2649 | status = nfs41_check_expired_locks(state); |
| 2650 | if (status != NFS_OK) |
| 2651 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2652 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2653 | if (status != NFS_OK) |
| 2654 | status = nfs4_open_expired(sp, state); |
| 2655 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2656 | } |
| 2657 | #endif |
| 2658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2660 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2661 | * fields corresponding to attributes that were used to store the verifier. |
| 2662 | * Make sure we clobber those fields in the later setattr call |
| 2663 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2664 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2665 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2666 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2667 | const u32 *attrset = opendata->o_res.attrset; |
| 2668 | |
| 2669 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2670 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2671 | sattr->ia_valid |= ATTR_ATIME; |
| 2672 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2673 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2674 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2675 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2676 | |
| 2677 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | 5637949 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2678 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2679 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2680 | sattr->ia_valid &= ~ATTR_MODE; |
| 2681 | |
| 2682 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2683 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2684 | } |
| 2685 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2686 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2687 | fmode_t fmode, |
| 2688 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2689 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2690 | { |
| 2691 | struct nfs4_state_owner *sp = opendata->owner; |
| 2692 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2693 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2694 | struct nfs4_state *state; |
| 2695 | unsigned int seq; |
| 2696 | int ret; |
| 2697 | |
| 2698 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2699 | |
| 2700 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2701 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2702 | goto out; |
| 2703 | |
| 2704 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2705 | ret = PTR_ERR(state); |
| 2706 | if (IS_ERR(state)) |
| 2707 | goto out; |
Trond Myklebust | 0465339 | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2708 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2709 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2710 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2711 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2712 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2713 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2714 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2715 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2716 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2717 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2718 | alias = d_exact_alias(dentry, state->inode); |
| 2719 | if (!alias) |
| 2720 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2721 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2722 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2723 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2724 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2725 | } |
| 2726 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2727 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2728 | } |
| 2729 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2730 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2731 | if (ret != 0) |
| 2732 | goto out; |
| 2733 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2734 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2735 | nfs_inode_attach_open_context(ctx); |
| 2736 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2737 | nfs4_schedule_stateid_recovery(server, state); |
| 2738 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2739 | out: |
| 2740 | return ret; |
| 2741 | } |
| 2742 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2743 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2744 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2746 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2747 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2748 | int flags, |
| 2749 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2750 | struct nfs4_label *label, |
| 2751 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | { |
| 2753 | struct nfs4_state_owner *sp; |
| 2754 | struct nfs4_state *state = NULL; |
| 2755 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2756 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2757 | struct dentry *dentry = ctx->dentry; |
| 2758 | struct rpc_cred *cred = ctx->cred; |
| 2759 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2760 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2761 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2762 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2763 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2767 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2768 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2770 | goto out_err; |
| 2771 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2772 | status = nfs4_recover_expired_lease(server); |
| 2773 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2774 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2775 | if (d_really_is_positive(dentry)) |
| 2776 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2777 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2778 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2779 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2780 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2781 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2782 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2783 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2785 | if (label) { |
| 2786 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2787 | if (IS_ERR(olabel)) { |
| 2788 | status = PTR_ERR(olabel); |
| 2789 | goto err_opendata_put; |
| 2790 | } |
| 2791 | } |
| 2792 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2793 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2794 | if (!opendata->f_attr.mdsthreshold) { |
| 2795 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2796 | if (!opendata->f_attr.mdsthreshold) |
| 2797 | goto err_free_label; |
| 2798 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2799 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2800 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2801 | if (d_really_is_positive(dentry)) |
| 2802 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2803 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2804 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2805 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2806 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2807 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2808 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2809 | 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] | 2810 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2811 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2812 | /* |
| 2813 | * send create attributes which was not set by open |
| 2814 | * with an extra setattr. |
| 2815 | */ |
| 2816 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2817 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2818 | status = nfs4_do_setattr(state->inode, cred, |
| 2819 | opendata->o_res.f_attr, sattr, |
| 2820 | state, label, olabel); |
| 2821 | if (status == 0) { |
| 2822 | nfs_setattr_update_inode(state->inode, sattr, |
| 2823 | opendata->o_res.f_attr); |
| 2824 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2825 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2826 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2827 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2828 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2829 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2830 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2831 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2832 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2833 | opendata->f_attr.mdsthreshold = NULL; |
| 2834 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2835 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2836 | nfs4_label_free(olabel); |
| 2837 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2838 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2841 | err_free_label: |
| 2842 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2843 | err_opendata_put: |
| 2844 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2845 | err_put_state_owner: |
| 2846 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | return status; |
| 2849 | } |
| 2850 | |
| 2851 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2852 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2853 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2854 | int flags, |
| 2855 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2856 | struct nfs4_label *label, |
| 2857 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2859 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | struct nfs4_exception exception = { }; |
| 2861 | struct nfs4_state *res; |
| 2862 | int status; |
| 2863 | |
| 2864 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2865 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2866 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2867 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | if (status == 0) |
| 2869 | break; |
| 2870 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2871 | * book-keeping w.r.t. state-changing operations |
| 2872 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2873 | * It is actually a sign of a bug on the client or on the server. |
| 2874 | * |
| 2875 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2876 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | * have unhashed the old state_owner for us, and that we can |
| 2878 | * therefore safely retry using a new one. We should still warn |
| 2879 | * the user though... |
| 2880 | */ |
| 2881 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2882 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2883 | " returned a bad sequence-id error!\n", |
| 2884 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | exception.retry = 1; |
| 2886 | continue; |
| 2887 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2888 | /* |
| 2889 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2890 | * state before it received the OPEN_CONFIRM. |
| 2891 | * Recover by retrying the request as per the discussion |
| 2892 | * on Page 181 of RFC3530. |
| 2893 | */ |
| 2894 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2895 | exception.retry = 1; |
| 2896 | continue; |
| 2897 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2898 | if (status == -EAGAIN) { |
| 2899 | /* We must have found a delegation */ |
| 2900 | exception.retry = 1; |
| 2901 | continue; |
| 2902 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2903 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2904 | continue; |
| 2905 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | status, &exception)); |
| 2907 | } while (exception.retry); |
| 2908 | return res; |
| 2909 | } |
| 2910 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2911 | static int _nfs4_do_setattr(struct inode *inode, |
| 2912 | struct nfs_setattrargs *arg, |
| 2913 | struct nfs_setattrres *res, |
| 2914 | struct rpc_cred *cred, |
| 2915 | struct nfs4_state *state) |
| 2916 | { |
| 2917 | struct nfs_server *server = NFS_SERVER(inode); |
| 2918 | struct rpc_message msg = { |
| 2919 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2920 | .rpc_argp = arg, |
| 2921 | .rpc_resp = res, |
| 2922 | .rpc_cred = cred, |
| 2923 | }; |
| 2924 | struct rpc_cred *delegation_cred = NULL; |
| 2925 | unsigned long timestamp = jiffies; |
| 2926 | fmode_t fmode; |
| 2927 | bool truncate; |
| 2928 | int status; |
| 2929 | |
| 2930 | nfs_fattr_init(res->fattr); |
| 2931 | |
| 2932 | /* Servers should only apply open mode checks for file size changes */ |
| 2933 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2934 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2935 | |
| 2936 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2937 | /* Use that stateid */ |
| 2938 | } else if (truncate && state != NULL) { |
| 2939 | struct nfs_lockowner lockowner = { |
| 2940 | .l_owner = current->files, |
| 2941 | .l_pid = current->tgid, |
| 2942 | }; |
| 2943 | if (!nfs4_valid_open_stateid(state)) |
| 2944 | return -EBADF; |
| 2945 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2946 | &arg->stateid, &delegation_cred) == -EIO) |
| 2947 | return -EBADF; |
| 2948 | } else |
| 2949 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2950 | if (delegation_cred) |
| 2951 | msg.rpc_cred = delegation_cred; |
| 2952 | |
| 2953 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2954 | |
| 2955 | put_rpccred(delegation_cred); |
| 2956 | if (status == 0 && state != NULL) |
| 2957 | renew_lease(server, timestamp); |
| 2958 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2959 | return status; |
| 2960 | } |
| 2961 | |
| 2962 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2963 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2964 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2965 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2967 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2969 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | .iap = sattr, |
| 2971 | .server = server, |
| 2972 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2973 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | }; |
| 2975 | struct nfs_setattrres res = { |
| 2976 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2977 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | .server = server, |
| 2979 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2980 | struct nfs4_exception exception = { |
| 2981 | .state = state, |
| 2982 | .inode = inode, |
| 2983 | .stateid = &arg.stateid, |
| 2984 | }; |
| 2985 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2987 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2988 | if (ilabel) |
| 2989 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2992 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2993 | switch (err) { |
| 2994 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2995 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2996 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2997 | "applying open mode checks to " |
| 2998 | "a SETATTR that is not " |
| 2999 | "changing file size.\n", |
| 3000 | server->nfs_client->cl_hostname); |
| 3001 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3002 | if (state && !(state->state & FMODE_WRITE)) { |
| 3003 | err = -EBADF; |
| 3004 | if (sattr->ia_valid & ATTR_OPEN) |
| 3005 | err = -EACCES; |
| 3006 | goto out; |
| 3007 | } |
| 3008 | } |
| 3009 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3011 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | return err; |
| 3013 | } |
| 3014 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3015 | static bool |
| 3016 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3017 | { |
| 3018 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3019 | return false; |
| 3020 | |
| 3021 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3022 | } |
| 3023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | struct nfs4_closedata { |
| 3025 | struct inode *inode; |
| 3026 | struct nfs4_state *state; |
| 3027 | struct nfs_closeargs arg; |
| 3028 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3029 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3030 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3031 | bool roc; |
| 3032 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | }; |
| 3034 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3035 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3036 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3037 | struct nfs4_closedata *calldata = data; |
| 3038 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3039 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3040 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3041 | if (calldata->roc) |
| 3042 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3043 | nfs4_put_open_state(calldata->state); |
| 3044 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3045 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3046 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3047 | kfree(calldata); |
| 3048 | } |
| 3049 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3050 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3052 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3055 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3057 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3058 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3059 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3060 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | /* hmm. we are done with the inode, and in the process of freeing |
| 3062 | * the state_owner. we keep this around to process errors |
| 3063 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | switch (task->tk_status) { |
| 3065 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3066 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3067 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3068 | pnfs_roc_set_barrier(state->inode, |
| 3069 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3070 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3071 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3072 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3074 | case -NFS4ERR_EXPIRED: |
| 3075 | nfs4_free_revoked_stateid(server, |
| 3076 | &calldata->arg.stateid, |
| 3077 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3078 | case -NFS4ERR_OLD_STATEID: |
| 3079 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3080 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3081 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3082 | rpc_restart_call_prepare(task); |
| 3083 | goto out_release; |
| 3084 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3085 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3086 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3088 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3089 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3090 | goto out_release; |
| 3091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3093 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3094 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3095 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3096 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3097 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3098 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3101 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3103 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3104 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3105 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3106 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3107 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3108 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3109 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3110 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3111 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3112 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3113 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3114 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3115 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3116 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3117 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3118 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3119 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3120 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3121 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3122 | if (state->n_rdonly == 0) |
| 3123 | call_close |= is_rdonly; |
| 3124 | else if (is_rdonly) |
| 3125 | calldata->arg.fmode |= FMODE_READ; |
| 3126 | if (state->n_wronly == 0) |
| 3127 | call_close |= is_wronly; |
| 3128 | else if (is_wronly) |
| 3129 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3130 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3131 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3132 | } else if (is_rdwr) |
| 3133 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3134 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3135 | if (!nfs4_valid_open_stateid(state) || |
| 3136 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3137 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3138 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3139 | |
| 3140 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3141 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3142 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3143 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3144 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3145 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 3146 | nfs_release_seqid(calldata->arg.seqid); |
| 3147 | goto out_wait; |
| 3148 | } |
| 3149 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3150 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3151 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3152 | if (calldata->roc) |
| 3153 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 3154 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3155 | calldata->arg.share_access = |
| 3156 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3157 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3158 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3159 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3160 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3161 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3162 | &calldata->arg.seq_args, |
| 3163 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3164 | task) != 0) |
| 3165 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3166 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3167 | return; |
| 3168 | out_no_action: |
| 3169 | task->tk_action = NULL; |
| 3170 | out_wait: |
| 3171 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3174 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3175 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3176 | .rpc_call_done = nfs4_close_done, |
| 3177 | .rpc_release = nfs4_free_closedata, |
| 3178 | }; |
| 3179 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3180 | static bool nfs4_roc(struct inode *inode) |
| 3181 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3182 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3183 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3184 | return pnfs_roc(inode); |
| 3185 | } |
| 3186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | /* |
| 3188 | * It is possible for data to be read/written from a mem-mapped file |
| 3189 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3190 | * This means that we can't safely call nfsv4 close on a file until |
| 3191 | * the inode is cleared. This in turn means that we are not good |
| 3192 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3193 | * share state even when we are done with one of the three share |
| 3194 | * stateid's in the inode. |
| 3195 | * |
| 3196 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3197 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3198 | 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] | 3199 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3200 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3201 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3203 | struct nfs4_state_owner *sp = state->owner; |
| 3204 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3205 | struct rpc_message msg = { |
| 3206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3207 | .rpc_cred = state->owner->so_cred, |
| 3208 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3209 | struct rpc_task_setup task_setup_data = { |
| 3210 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3211 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3212 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3213 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3214 | .flags = RPC_TASK_ASYNC, |
| 3215 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3216 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3218 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3219 | &task_setup_data.rpc_client, &msg); |
| 3220 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3221 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3223 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3224 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3225 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3227 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3229 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3230 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3231 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3232 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3233 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3234 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3235 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3236 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3237 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3238 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3239 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3240 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3241 | msg.rpc_argp = &calldata->arg; |
| 3242 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3243 | task_setup_data.callback_data = calldata; |
| 3244 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3245 | if (IS_ERR(task)) |
| 3246 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3247 | status = 0; |
| 3248 | if (wait) |
| 3249 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3250 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3251 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3252 | out_free_calldata: |
| 3253 | kfree(calldata); |
| 3254 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3255 | nfs4_put_open_state(state); |
| 3256 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3257 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3260 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3261 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3262 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3265 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3266 | |
| 3267 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3269 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3270 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3271 | |
| 3272 | nfs4_label_release_security(label); |
| 3273 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3274 | if (IS_ERR(state)) |
| 3275 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3276 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3279 | 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] | 3280 | { |
| 3281 | if (ctx->state == NULL) |
| 3282 | return; |
| 3283 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3284 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3285 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3286 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3289 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3290 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3291 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3294 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3295 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3296 | struct nfs4_server_caps_arg args = { |
| 3297 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3298 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3299 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | struct nfs4_server_caps_res res = {}; |
| 3301 | struct rpc_message msg = { |
| 3302 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3303 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | .rpc_resp = &res, |
| 3305 | }; |
| 3306 | int status; |
| 3307 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3308 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3309 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3310 | FATTR4_WORD0_LINK_SUPPORT | |
| 3311 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3312 | FATTR4_WORD0_ACLSUPPORT; |
| 3313 | if (minorversion) |
| 3314 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3315 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3316 | 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] | 3317 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3318 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3319 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3320 | case 0: |
| 3321 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3322 | res.attr_bitmask[2] = 0; |
| 3323 | break; |
| 3324 | case 1: |
| 3325 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3326 | break; |
| 3327 | case 2: |
| 3328 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3331 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3332 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3333 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3334 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3335 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3336 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3337 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3338 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | server->caps |= NFS_CAP_ACLS; |
| 3340 | if (res.has_links != 0) |
| 3341 | server->caps |= NFS_CAP_HARDLINKS; |
| 3342 | if (res.has_symlinks != 0) |
| 3343 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3344 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3345 | server->caps |= NFS_CAP_FILEID; |
| 3346 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3347 | server->caps |= NFS_CAP_MODE; |
| 3348 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3349 | server->caps |= NFS_CAP_NLINK; |
| 3350 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3351 | server->caps |= NFS_CAP_OWNER; |
| 3352 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3353 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3354 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3355 | server->caps |= NFS_CAP_ATIME; |
| 3356 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3357 | server->caps |= NFS_CAP_CTIME; |
| 3358 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3359 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3360 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3361 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3362 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3363 | #endif |
| 3364 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3365 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3366 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3367 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3368 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3369 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3370 | 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] | 3371 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3372 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3373 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3375 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | return status; |
| 3379 | } |
| 3380 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3381 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | { |
| 3383 | struct nfs4_exception exception = { }; |
| 3384 | int err; |
| 3385 | do { |
| 3386 | err = nfs4_handle_exception(server, |
| 3387 | _nfs4_server_capabilities(server, fhandle), |
| 3388 | &exception); |
| 3389 | } while (exception.retry); |
| 3390 | return err; |
| 3391 | } |
| 3392 | |
| 3393 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3394 | struct nfs_fsinfo *info) |
| 3395 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3396 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3398 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | }; |
| 3400 | struct nfs4_lookup_res res = { |
| 3401 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3402 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | .fh = fhandle, |
| 3404 | }; |
| 3405 | struct rpc_message msg = { |
| 3406 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3407 | .rpc_argp = &args, |
| 3408 | .rpc_resp = &res, |
| 3409 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3410 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3411 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3412 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3413 | /* |
| 3414 | * Process the label in the upcoming getfattr |
| 3415 | */ |
| 3416 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3417 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3418 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3419 | 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] | 3420 | } |
| 3421 | |
| 3422 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3423 | struct nfs_fsinfo *info) |
| 3424 | { |
| 3425 | struct nfs4_exception exception = { }; |
| 3426 | int err; |
| 3427 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3428 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3429 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3430 | switch (err) { |
| 3431 | case 0: |
| 3432 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3433 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3434 | default: |
| 3435 | err = nfs4_handle_exception(server, err, &exception); |
| 3436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3438 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | return err; |
| 3440 | } |
| 3441 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3442 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3443 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3444 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3445 | struct rpc_auth_create_args auth_args = { |
| 3446 | .pseudoflavor = flavor, |
| 3447 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3448 | struct rpc_auth *auth; |
| 3449 | int ret; |
| 3450 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3451 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3452 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3453 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3454 | goto out; |
| 3455 | } |
| 3456 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3457 | out: |
| 3458 | return ret; |
| 3459 | } |
| 3460 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3461 | /* |
| 3462 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3463 | * |
| 3464 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3465 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3466 | * |
| 3467 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3468 | * negative errno value. |
| 3469 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3470 | 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] | 3471 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3473 | /* Per 3530bis 15.33.5 */ |
| 3474 | static const rpc_authflavor_t flav_array[] = { |
| 3475 | RPC_AUTH_GSS_KRB5P, |
| 3476 | RPC_AUTH_GSS_KRB5I, |
| 3477 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3478 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3479 | RPC_AUTH_NULL, |
| 3480 | }; |
| 3481 | int status = -EPERM; |
| 3482 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3484 | if (server->auth_info.flavor_len > 0) { |
| 3485 | /* try each flavor specified by user */ |
| 3486 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3487 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3488 | server->auth_info.flavors[i]); |
| 3489 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3490 | continue; |
| 3491 | break; |
| 3492 | } |
| 3493 | } else { |
| 3494 | /* no flavors specified by user, try default list */ |
| 3495 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3496 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3497 | flav_array[i]); |
| 3498 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3499 | continue; |
| 3500 | break; |
| 3501 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3502 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3503 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3504 | /* |
| 3505 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3506 | * to access the mount. It could also mean that we tried to mount |
| 3507 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3508 | * existing mount programs don't handle -EACCES very well so it should |
| 3509 | * be mapped to -EPERM instead. |
| 3510 | */ |
| 3511 | if (status == -EACCES) |
| 3512 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3513 | return status; |
| 3514 | } |
| 3515 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3516 | /** |
| 3517 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3518 | * @server: initialized nfs_server handle |
| 3519 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3520 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3521 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3522 | * |
| 3523 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3524 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3525 | 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] | 3526 | struct nfs_fsinfo *info, |
| 3527 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3528 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3529 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3530 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3531 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3532 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3533 | |
| 3534 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3535 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3536 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | if (status == 0) |
| 3539 | status = nfs4_server_capabilities(server, fhandle); |
| 3540 | if (status == 0) |
| 3541 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3542 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3543 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3546 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3547 | struct nfs_fsinfo *info) |
| 3548 | { |
| 3549 | int error; |
| 3550 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3551 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3552 | |
| 3553 | error = nfs4_server_capabilities(server, mntfh); |
| 3554 | if (error < 0) { |
| 3555 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3556 | return error; |
| 3557 | } |
| 3558 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3559 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3560 | if (IS_ERR(label)) |
| 3561 | return PTR_ERR(label); |
| 3562 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3563 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3564 | if (error < 0) { |
| 3565 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3566 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3570 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3571 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3572 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3573 | err_free_label: |
| 3574 | nfs4_label_free(label); |
| 3575 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3576 | return error; |
| 3577 | } |
| 3578 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3579 | /* |
| 3580 | * Get locations and (maybe) other attributes of a referral. |
| 3581 | * Note that we'll actually follow the referral later when |
| 3582 | * we detect fsid mismatch in inode revalidation |
| 3583 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3584 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3585 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3586 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3587 | { |
| 3588 | int status = -ENOMEM; |
| 3589 | struct page *page = NULL; |
| 3590 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3591 | |
| 3592 | page = alloc_page(GFP_KERNEL); |
| 3593 | if (page == NULL) |
| 3594 | goto out; |
| 3595 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3596 | if (locations == NULL) |
| 3597 | goto out; |
| 3598 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3599 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3600 | if (status != 0) |
| 3601 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3602 | |
| 3603 | /* |
| 3604 | * If the fsid didn't change, this is a migration event, not a |
| 3605 | * referral. Cause us to drop into the exception handler, which |
| 3606 | * will kick off migration recovery. |
| 3607 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3608 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3609 | dprintk("%s: server did not return a different fsid for" |
| 3610 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3611 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3612 | goto out; |
| 3613 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3614 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3615 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3616 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3617 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3618 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3619 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3620 | out: |
| 3621 | if (page) |
| 3622 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3623 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3624 | return status; |
| 3625 | } |
| 3626 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3627 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3628 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | { |
| 3630 | struct nfs4_getattr_arg args = { |
| 3631 | .fh = fhandle, |
| 3632 | .bitmask = server->attr_bitmask, |
| 3633 | }; |
| 3634 | struct nfs4_getattr_res res = { |
| 3635 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3636 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | .server = server, |
| 3638 | }; |
| 3639 | struct rpc_message msg = { |
| 3640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3641 | .rpc_argp = &args, |
| 3642 | .rpc_resp = &res, |
| 3643 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3644 | |
| 3645 | args.bitmask = nfs4_bitmask(server, label); |
| 3646 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3647 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3648 | 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] | 3649 | } |
| 3650 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3651 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3652 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | { |
| 3654 | struct nfs4_exception exception = { }; |
| 3655 | int err; |
| 3656 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3657 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3658 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3659 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | &exception); |
| 3661 | } while (exception.retry); |
| 3662 | return err; |
| 3663 | } |
| 3664 | |
| 3665 | /* |
| 3666 | * The file is not closed if it is opened due to the a request to change |
| 3667 | * the size of the file. The open call will not be needed once the |
| 3668 | * VFS layer lookup-intents are implemented. |
| 3669 | * |
| 3670 | * Close is called when the inode is destroyed. |
| 3671 | * If we haven't opened the file for O_WRONLY, we |
| 3672 | * need to in the size_change case to obtain a stateid. |
| 3673 | * |
| 3674 | * Got race? |
| 3675 | * Because OPEN is always done by name in nfsv4, it is |
| 3676 | * possible that we opened a different file by the same |
| 3677 | * name. We can recognize this race condition, but we |
| 3678 | * can't do anything about it besides returning an error. |
| 3679 | * |
| 3680 | * This will be fixed with VFS changes (lookup-intent). |
| 3681 | */ |
| 3682 | static int |
| 3683 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3684 | struct iattr *sattr) |
| 3685 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3686 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3687 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3688 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3689 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | int status; |
| 3691 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3692 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3693 | sattr->ia_valid & ATTR_SIZE && |
| 3694 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3695 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3696 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3697 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3699 | /* Deal with open(O_TRUNC) */ |
| 3700 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3701 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3702 | |
| 3703 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3704 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3705 | return 0; |
| 3706 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3707 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3708 | if (sattr->ia_valid & ATTR_FILE) { |
| 3709 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3710 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3711 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3712 | if (ctx) { |
| 3713 | cred = ctx->cred; |
| 3714 | state = ctx->state; |
| 3715 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3716 | } |
| 3717 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3718 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3719 | if (IS_ERR(label)) |
| 3720 | return PTR_ERR(label); |
| 3721 | |
| 3722 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3723 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3724 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3725 | nfs_setsecurity(inode, fattr, label); |
| 3726 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3727 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | return status; |
| 3729 | } |
| 3730 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3731 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3732 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3733 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3734 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3735 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3736 | int status; |
| 3737 | struct nfs4_lookup_arg args = { |
| 3738 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3739 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3740 | .name = name, |
| 3741 | }; |
| 3742 | struct nfs4_lookup_res res = { |
| 3743 | .server = server, |
| 3744 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3745 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3746 | .fh = fhandle, |
| 3747 | }; |
| 3748 | struct rpc_message msg = { |
| 3749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3750 | .rpc_argp = &args, |
| 3751 | .rpc_resp = &res, |
| 3752 | }; |
| 3753 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3754 | args.bitmask = nfs4_bitmask(server, label); |
| 3755 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3756 | nfs_fattr_init(fattr); |
| 3757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3759 | 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] | 3760 | dprintk("NFS reply lookup: %d\n", status); |
| 3761 | return status; |
| 3762 | } |
| 3763 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3764 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3765 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3766 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3767 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3768 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3769 | fattr->nlink = 2; |
| 3770 | } |
| 3771 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3772 | 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] | 3773 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3774 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3775 | { |
| 3776 | struct nfs4_exception exception = { }; |
| 3777 | struct rpc_clnt *client = *clnt; |
| 3778 | int err; |
| 3779 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3780 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3781 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3782 | switch (err) { |
| 3783 | case -NFS4ERR_BADNAME: |
| 3784 | err = -ENOENT; |
| 3785 | goto out; |
| 3786 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3787 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3788 | if (err == -NFS4ERR_MOVED) |
| 3789 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3790 | goto out; |
| 3791 | case -NFS4ERR_WRONGSEC: |
| 3792 | err = -EPERM; |
| 3793 | if (client != *clnt) |
| 3794 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3795 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3796 | if (IS_ERR(client)) |
| 3797 | return PTR_ERR(client); |
| 3798 | |
| 3799 | exception.retry = 1; |
| 3800 | break; |
| 3801 | default: |
| 3802 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3803 | } |
| 3804 | } while (exception.retry); |
| 3805 | |
| 3806 | out: |
| 3807 | if (err == 0) |
| 3808 | *clnt = client; |
| 3809 | else if (client != *clnt) |
| 3810 | rpc_shutdown_client(client); |
| 3811 | |
| 3812 | return err; |
| 3813 | } |
| 3814 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3815 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3816 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3817 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3819 | int status; |
| 3820 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3821 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3822 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3823 | if (client != NFS_CLIENT(dir)) { |
| 3824 | rpc_shutdown_client(client); |
| 3825 | nfs_fixup_secinfo_attributes(fattr); |
| 3826 | } |
| 3827 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3830 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3831 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3832 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3833 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3834 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3835 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3836 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3837 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3838 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3839 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3840 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3841 | } |
| 3842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3844 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3845 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | struct nfs4_accessargs args = { |
| 3847 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3848 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3850 | struct nfs4_accessres res = { |
| 3851 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3852 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | struct rpc_message msg = { |
| 3854 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3855 | .rpc_argp = &args, |
| 3856 | .rpc_resp = &res, |
| 3857 | .rpc_cred = entry->cred, |
| 3858 | }; |
| 3859 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3860 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | |
| 3862 | /* |
| 3863 | * Determine which access bits we want to ask for... |
| 3864 | */ |
| 3865 | if (mode & MAY_READ) |
| 3866 | args.access |= NFS4_ACCESS_READ; |
| 3867 | if (S_ISDIR(inode->i_mode)) { |
| 3868 | if (mode & MAY_WRITE) |
| 3869 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3870 | if (mode & MAY_EXEC) |
| 3871 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3872 | } else { |
| 3873 | if (mode & MAY_WRITE) |
| 3874 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3875 | if (mode & MAY_EXEC) |
| 3876 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3877 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3878 | |
| 3879 | res.fattr = nfs_alloc_fattr(); |
| 3880 | if (res.fattr == NULL) |
| 3881 | return -ENOMEM; |
| 3882 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3883 | 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] | 3884 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3885 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3886 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3888 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | return status; |
| 3890 | } |
| 3891 | |
| 3892 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3893 | { |
| 3894 | struct nfs4_exception exception = { }; |
| 3895 | int err; |
| 3896 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3897 | err = _nfs4_proc_access(inode, entry); |
| 3898 | trace_nfs4_access(inode, err); |
| 3899 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | &exception); |
| 3901 | } while (exception.retry); |
| 3902 | return err; |
| 3903 | } |
| 3904 | |
| 3905 | /* |
| 3906 | * TODO: For the time being, we don't try to get any attributes |
| 3907 | * along with any of the zero-copy operations READ, READDIR, |
| 3908 | * READLINK, WRITE. |
| 3909 | * |
| 3910 | * In the case of the first three, we want to put the GETATTR |
| 3911 | * after the read-type operation -- this is because it is hard |
| 3912 | * to predict the length of a GETATTR response in v4, and thus |
| 3913 | * align the READ data correctly. This means that the GETATTR |
| 3914 | * may end up partially falling into the page cache, and we should |
| 3915 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3916 | * To do this efficiently, we need to know the total length |
| 3917 | * of data received, which doesn't seem to be available outside |
| 3918 | * of the RPC layer. |
| 3919 | * |
| 3920 | * In the case of WRITE, we also want to put the GETATTR after |
| 3921 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3922 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | * |
| 3924 | * Both of these changes to the XDR layer would in fact be quite |
| 3925 | * minor, but I decided to leave them for a subsequent patch. |
| 3926 | */ |
| 3927 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3928 | unsigned int pgbase, unsigned int pglen) |
| 3929 | { |
| 3930 | struct nfs4_readlink args = { |
| 3931 | .fh = NFS_FH(inode), |
| 3932 | .pgbase = pgbase, |
| 3933 | .pglen = pglen, |
| 3934 | .pages = &page, |
| 3935 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3936 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | struct rpc_message msg = { |
| 3938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3939 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3940 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | }; |
| 3942 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3943 | 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] | 3944 | } |
| 3945 | |
| 3946 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3947 | unsigned int pgbase, unsigned int pglen) |
| 3948 | { |
| 3949 | struct nfs4_exception exception = { }; |
| 3950 | int err; |
| 3951 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3952 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3953 | trace_nfs4_readlink(inode, err); |
| 3954 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | &exception); |
| 3956 | } while (exception.retry); |
| 3957 | return err; |
| 3958 | } |
| 3959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3961 | * 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] | 3962 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | static int |
| 3964 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3965 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3967 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3968 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | int status = 0; |
| 3971 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3972 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3973 | if (IS_ERR(ctx)) |
| 3974 | return PTR_ERR(ctx); |
| 3975 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3976 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3977 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3978 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3979 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | if (IS_ERR(state)) { |
| 3981 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3982 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3985 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3986 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | return status; |
| 3988 | } |
| 3989 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3990 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3992 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3993 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3995 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3997 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3998 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3999 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4002 | .rpc_argp = &args, |
| 4003 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4005 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4006 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4007 | 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] | 4008 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4009 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | return status; |
| 4011 | } |
| 4012 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4013 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | { |
| 4015 | struct nfs4_exception exception = { }; |
| 4016 | int err; |
| 4017 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4018 | err = _nfs4_proc_remove(dir, name); |
| 4019 | trace_nfs4_remove(dir, name, err); |
| 4020 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | &exception); |
| 4022 | } while (exception.retry); |
| 4023 | return err; |
| 4024 | } |
| 4025 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4026 | 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] | 4027 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4028 | struct nfs_server *server = NFS_SERVER(dir); |
| 4029 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4030 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4032 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4034 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4035 | |
| 4036 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4039 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4040 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4041 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4042 | &data->args.seq_args, |
| 4043 | &data->res.seq_res, |
| 4044 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | } |
| 4046 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4047 | 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] | 4048 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4049 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4050 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4051 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4052 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4053 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4054 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4055 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4056 | return 0; |
| 4057 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4058 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4061 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4062 | { |
| 4063 | struct nfs_server *server = NFS_SERVER(dir); |
| 4064 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4065 | struct nfs_renameres *res = msg->rpc_resp; |
| 4066 | |
| 4067 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4068 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4069 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4070 | } |
| 4071 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4072 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4073 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4074 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4075 | &data->args.seq_args, |
| 4076 | &data->res.seq_res, |
| 4077 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4081 | struct inode *new_dir) |
| 4082 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4083 | struct nfs_renamedata *data = task->tk_calldata; |
| 4084 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4085 | |
| 4086 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4087 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4088 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4089 | return 0; |
| 4090 | |
| 4091 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4092 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4093 | return 1; |
| 4094 | } |
| 4095 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4096 | 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] | 4097 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4098 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | struct nfs4_link_arg arg = { |
| 4100 | .fh = NFS_FH(inode), |
| 4101 | .dir_fh = NFS_FH(dir), |
| 4102 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4103 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4105 | struct nfs4_link_res res = { |
| 4106 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4107 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4108 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | struct rpc_message msg = { |
| 4110 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4111 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4112 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4114 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4116 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4117 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4118 | goto out; |
| 4119 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4120 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4121 | if (IS_ERR(res.label)) { |
| 4122 | status = PTR_ERR(res.label); |
| 4123 | goto out; |
| 4124 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4125 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4126 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4127 | 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] | 4128 | if (!status) { |
| 4129 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4130 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4131 | if (!status) |
| 4132 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4133 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4134 | |
| 4135 | |
| 4136 | nfs4_label_free(res.label); |
| 4137 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4138 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4139 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | return status; |
| 4141 | } |
| 4142 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4143 | 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] | 4144 | { |
| 4145 | struct nfs4_exception exception = { }; |
| 4146 | int err; |
| 4147 | do { |
| 4148 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4149 | _nfs4_proc_link(inode, dir, name), |
| 4150 | &exception); |
| 4151 | } while (exception.retry); |
| 4152 | return err; |
| 4153 | } |
| 4154 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4155 | struct nfs4_createdata { |
| 4156 | struct rpc_message msg; |
| 4157 | struct nfs4_create_arg arg; |
| 4158 | struct nfs4_create_res res; |
| 4159 | struct nfs_fh fh; |
| 4160 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4161 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4162 | }; |
| 4163 | |
| 4164 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4165 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4166 | { |
| 4167 | struct nfs4_createdata *data; |
| 4168 | |
| 4169 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4170 | if (data != NULL) { |
| 4171 | struct nfs_server *server = NFS_SERVER(dir); |
| 4172 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4173 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4174 | if (IS_ERR(data->label)) |
| 4175 | goto out_free; |
| 4176 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4177 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4178 | data->msg.rpc_argp = &data->arg; |
| 4179 | data->msg.rpc_resp = &data->res; |
| 4180 | data->arg.dir_fh = NFS_FH(dir); |
| 4181 | data->arg.server = server; |
| 4182 | data->arg.name = name; |
| 4183 | data->arg.attrs = sattr; |
| 4184 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4185 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4186 | data->res.server = server; |
| 4187 | data->res.fh = &data->fh; |
| 4188 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4189 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4190 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4191 | } |
| 4192 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4193 | out_free: |
| 4194 | kfree(data); |
| 4195 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4199 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4200 | 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] | 4201 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4202 | if (status == 0) { |
| 4203 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4204 | 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] | 4205 | } |
| 4206 | return status; |
| 4207 | } |
| 4208 | |
| 4209 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4210 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4211 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4212 | kfree(data); |
| 4213 | } |
| 4214 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4215 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4216 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4217 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4219 | struct nfs4_createdata *data; |
| 4220 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4222 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4223 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4224 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4225 | status = -ENOMEM; |
| 4226 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4227 | if (data == NULL) |
| 4228 | goto out; |
| 4229 | |
| 4230 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4231 | data->arg.u.symlink.pages = &page; |
| 4232 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4233 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4235 | status = nfs4_do_create(dir, dentry, data); |
| 4236 | |
| 4237 | nfs4_free_createdata(data); |
| 4238 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | return status; |
| 4240 | } |
| 4241 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4242 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4243 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | { |
| 4245 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4246 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4248 | |
| 4249 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4252 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4253 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4254 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | &exception); |
| 4256 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4257 | |
| 4258 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | return err; |
| 4260 | } |
| 4261 | |
| 4262 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4263 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4265 | struct nfs4_createdata *data; |
| 4266 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4268 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4269 | if (data == NULL) |
| 4270 | goto out; |
| 4271 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4272 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4273 | status = nfs4_do_create(dir, dentry, data); |
| 4274 | |
| 4275 | nfs4_free_createdata(data); |
| 4276 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | return status; |
| 4278 | } |
| 4279 | |
| 4280 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4281 | struct iattr *sattr) |
| 4282 | { |
| 4283 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4284 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4286 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4287 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4288 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4289 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4291 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4292 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4293 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | &exception); |
| 4295 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4296 | nfs4_label_release_security(label); |
| 4297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | return err; |
| 4299 | } |
| 4300 | |
| 4301 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4302 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4304 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | struct nfs4_readdir_arg args = { |
| 4306 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4307 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | .pgbase = 0, |
| 4309 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4310 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4311 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | }; |
| 4313 | struct nfs4_readdir_res res; |
| 4314 | struct rpc_message msg = { |
| 4315 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4316 | .rpc_argp = &args, |
| 4317 | .rpc_resp = &res, |
| 4318 | .rpc_cred = cred, |
| 4319 | }; |
| 4320 | int status; |
| 4321 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4322 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4323 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4324 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4325 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4327 | 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] | 4328 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4329 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4330 | status += args.pgbase; |
| 4331 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4332 | |
| 4333 | nfs_invalidate_atime(dir); |
| 4334 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4335 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | return status; |
| 4337 | } |
| 4338 | |
| 4339 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4340 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | { |
| 4342 | struct nfs4_exception exception = { }; |
| 4343 | int err; |
| 4344 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4345 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4346 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4347 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4348 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | &exception); |
| 4350 | } while (exception.retry); |
| 4351 | return err; |
| 4352 | } |
| 4353 | |
| 4354 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4355 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4357 | struct nfs4_createdata *data; |
| 4358 | int mode = sattr->ia_mode; |
| 4359 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4361 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4362 | if (data == NULL) |
| 4363 | goto out; |
| 4364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4366 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4368 | data->arg.ftype = NF4BLK; |
| 4369 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4370 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | } |
| 4372 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4373 | data->arg.ftype = NF4CHR; |
| 4374 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4375 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4376 | } else if (!S_ISSOCK(mode)) { |
| 4377 | status = -EINVAL; |
| 4378 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4380 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4381 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4382 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4383 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4384 | nfs4_free_createdata(data); |
| 4385 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | return status; |
| 4387 | } |
| 4388 | |
| 4389 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4390 | struct iattr *sattr, dev_t rdev) |
| 4391 | { |
| 4392 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4393 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4395 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4396 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4397 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4398 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4400 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4401 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4402 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | &exception); |
| 4404 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4405 | |
| 4406 | nfs4_label_release_security(label); |
| 4407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | return err; |
| 4409 | } |
| 4410 | |
| 4411 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4412 | struct nfs_fsstat *fsstat) |
| 4413 | { |
| 4414 | struct nfs4_statfs_arg args = { |
| 4415 | .fh = fhandle, |
| 4416 | .bitmask = server->attr_bitmask, |
| 4417 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4418 | struct nfs4_statfs_res res = { |
| 4419 | .fsstat = fsstat, |
| 4420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | struct rpc_message msg = { |
| 4422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4423 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | }; |
| 4426 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4427 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4428 | 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] | 4429 | } |
| 4430 | |
| 4431 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4432 | { |
| 4433 | struct nfs4_exception exception = { }; |
| 4434 | int err; |
| 4435 | do { |
| 4436 | err = nfs4_handle_exception(server, |
| 4437 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4438 | &exception); |
| 4439 | } while (exception.retry); |
| 4440 | return err; |
| 4441 | } |
| 4442 | |
| 4443 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4444 | struct nfs_fsinfo *fsinfo) |
| 4445 | { |
| 4446 | struct nfs4_fsinfo_arg args = { |
| 4447 | .fh = fhandle, |
| 4448 | .bitmask = server->attr_bitmask, |
| 4449 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4450 | struct nfs4_fsinfo_res res = { |
| 4451 | .fsinfo = fsinfo, |
| 4452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | struct rpc_message msg = { |
| 4454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4455 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4456 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | }; |
| 4458 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4459 | 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] | 4460 | } |
| 4461 | |
| 4462 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4463 | { |
| 4464 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4465 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | int err; |
| 4467 | |
| 4468 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4469 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4470 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4471 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4472 | nfs4_set_lease_period(server->nfs_client, |
| 4473 | fsinfo->lease_time * HZ, |
| 4474 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4475 | break; |
| 4476 | } |
| 4477 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | } while (exception.retry); |
| 4479 | return err; |
| 4480 | } |
| 4481 | |
| 4482 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4483 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4484 | int error; |
| 4485 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4486 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4487 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4488 | if (error == 0) { |
| 4489 | /* block layout checks this! */ |
| 4490 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4491 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4492 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4493 | |
| 4494 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4498 | struct nfs_pathconf *pathconf) |
| 4499 | { |
| 4500 | struct nfs4_pathconf_arg args = { |
| 4501 | .fh = fhandle, |
| 4502 | .bitmask = server->attr_bitmask, |
| 4503 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4504 | struct nfs4_pathconf_res res = { |
| 4505 | .pathconf = pathconf, |
| 4506 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | struct rpc_message msg = { |
| 4508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4509 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4510 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | }; |
| 4512 | |
| 4513 | /* None of the pathconf attributes are mandatory to implement */ |
| 4514 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4515 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4516 | return 0; |
| 4517 | } |
| 4518 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4519 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4520 | 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] | 4521 | } |
| 4522 | |
| 4523 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4524 | struct nfs_pathconf *pathconf) |
| 4525 | { |
| 4526 | struct nfs4_exception exception = { }; |
| 4527 | int err; |
| 4528 | |
| 4529 | do { |
| 4530 | err = nfs4_handle_exception(server, |
| 4531 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4532 | &exception); |
| 4533 | } while (exception.retry); |
| 4534 | return err; |
| 4535 | } |
| 4536 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4537 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4538 | const struct nfs_open_context *ctx, |
| 4539 | const struct nfs_lock_context *l_ctx, |
| 4540 | fmode_t fmode) |
| 4541 | { |
| 4542 | const struct nfs_lockowner *lockowner = NULL; |
| 4543 | |
| 4544 | if (l_ctx != NULL) |
| 4545 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4546 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4547 | } |
| 4548 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4549 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4550 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4551 | const struct nfs_open_context *ctx, |
| 4552 | const struct nfs_lock_context *l_ctx, |
| 4553 | fmode_t fmode) |
| 4554 | { |
| 4555 | nfs4_stateid current_stateid; |
| 4556 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4557 | /* If the current stateid represents a lost lock, then exit */ |
| 4558 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4559 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4560 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4561 | } |
| 4562 | |
| 4563 | static bool nfs4_error_stateid_expired(int err) |
| 4564 | { |
| 4565 | switch (err) { |
| 4566 | case -NFS4ERR_DELEG_REVOKED: |
| 4567 | case -NFS4ERR_ADMIN_REVOKED: |
| 4568 | case -NFS4ERR_BAD_STATEID: |
| 4569 | case -NFS4ERR_STALE_STATEID: |
| 4570 | case -NFS4ERR_OLD_STATEID: |
| 4571 | case -NFS4ERR_OPENMODE: |
| 4572 | case -NFS4ERR_EXPIRED: |
| 4573 | return true; |
| 4574 | } |
| 4575 | return false; |
| 4576 | } |
| 4577 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4578 | 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] | 4579 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4580 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4582 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4583 | if (task->tk_status < 0) { |
| 4584 | struct nfs4_exception exception = { |
| 4585 | .inode = hdr->inode, |
| 4586 | .state = hdr->args.context->state, |
| 4587 | .stateid = &hdr->args.stateid, |
| 4588 | }; |
| 4589 | task->tk_status = nfs4_async_handle_exception(task, |
| 4590 | server, task->tk_status, &exception); |
| 4591 | if (exception.retry) { |
| 4592 | rpc_restart_call_prepare(task); |
| 4593 | return -EAGAIN; |
| 4594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4598 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4599 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4602 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4603 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4604 | { |
| 4605 | |
| 4606 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4607 | nfs4_stateid_is_current(&args->stateid, |
| 4608 | args->context, |
| 4609 | args->lock_context, |
| 4610 | FMODE_READ)) |
| 4611 | return false; |
| 4612 | rpc_restart_call_prepare(task); |
| 4613 | return true; |
| 4614 | } |
| 4615 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4616 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4617 | { |
| 4618 | |
| 4619 | dprintk("--> %s\n", __func__); |
| 4620 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4621 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4622 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4623 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4624 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4625 | if (task->tk_status > 0) |
| 4626 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4627 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4628 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4631 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4632 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4634 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4635 | if (!hdr->pgio_done_cb) |
| 4636 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4637 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4638 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4641 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4642 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4643 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4644 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4645 | &hdr->args.seq_args, |
| 4646 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4647 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4648 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4649 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4650 | hdr->args.lock_context, |
| 4651 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4652 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4653 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4654 | return -EIO; |
| 4655 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4658 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4659 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4662 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4663 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4664 | if (task->tk_status < 0) { |
| 4665 | struct nfs4_exception exception = { |
| 4666 | .inode = hdr->inode, |
| 4667 | .state = hdr->args.context->state, |
| 4668 | .stateid = &hdr->args.stateid, |
| 4669 | }; |
| 4670 | task->tk_status = nfs4_async_handle_exception(task, |
| 4671 | NFS_SERVER(inode), task->tk_status, |
| 4672 | &exception); |
| 4673 | if (exception.retry) { |
| 4674 | rpc_restart_call_prepare(task); |
| 4675 | return -EAGAIN; |
| 4676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4678 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4679 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4680 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4681 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4682 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4685 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4686 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4687 | { |
| 4688 | |
| 4689 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4690 | nfs4_stateid_is_current(&args->stateid, |
| 4691 | args->context, |
| 4692 | args->lock_context, |
| 4693 | FMODE_WRITE)) |
| 4694 | return false; |
| 4695 | rpc_restart_call_prepare(task); |
| 4696 | return true; |
| 4697 | } |
| 4698 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4699 | 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] | 4700 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4701 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4702 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4703 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4704 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4705 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4706 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4709 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4711 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4712 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4713 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4714 | return false; |
| 4715 | /* Otherwise, request attributes if and only if we don't hold |
| 4716 | * a delegation |
| 4717 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4718 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4719 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4720 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4721 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4722 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4724 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4725 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4726 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4727 | hdr->args.bitmask = NULL; |
| 4728 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4729 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4730 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4731 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4732 | if (!hdr->pgio_done_cb) |
| 4733 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4734 | hdr->res.server = server; |
| 4735 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4737 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4738 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4741 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4742 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4743 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4744 | &data->args.seq_args, |
| 4745 | &data->res.seq_res, |
| 4746 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4749 | 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] | 4750 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4752 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4753 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4754 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4755 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4756 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4757 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4759 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | } |
| 4761 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4762 | 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] | 4763 | { |
| 4764 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4765 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4766 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4769 | 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] | 4770 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4771 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4772 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4773 | if (data->commit_done_cb == NULL) |
| 4774 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4775 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4776 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4777 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4780 | struct nfs4_renewdata { |
| 4781 | struct nfs_client *client; |
| 4782 | unsigned long timestamp; |
| 4783 | }; |
| 4784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | /* |
| 4786 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4787 | * standalone procedure for queueing an asynchronous RENEW. |
| 4788 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4789 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4790 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4791 | struct nfs4_renewdata *data = calldata; |
| 4792 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4793 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4794 | if (atomic_read(&clp->cl_count) > 1) |
| 4795 | nfs4_schedule_state_renewal(clp); |
| 4796 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4797 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4798 | } |
| 4799 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4800 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4802 | struct nfs4_renewdata *data = calldata; |
| 4803 | struct nfs_client *clp = data->client; |
| 4804 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4806 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4807 | switch (task->tk_status) { |
| 4808 | case 0: |
| 4809 | break; |
| 4810 | case -NFS4ERR_LEASE_MOVED: |
| 4811 | nfs4_schedule_lease_moved_recovery(clp); |
| 4812 | break; |
| 4813 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4814 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4815 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4816 | return; |
| 4817 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4818 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4819 | return; |
| 4820 | } |
| 4821 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4823 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4826 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4827 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4828 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4829 | }; |
| 4830 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4831 | 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] | 4832 | { |
| 4833 | struct rpc_message msg = { |
| 4834 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4835 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4836 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4838 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4840 | if (renew_flags == 0) |
| 4841 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4842 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4843 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4844 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4845 | if (data == NULL) |
| 4846 | return -ENOMEM; |
| 4847 | data->client = clp; |
| 4848 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4849 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4850 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4853 | 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] | 4854 | { |
| 4855 | struct rpc_message msg = { |
| 4856 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4857 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4858 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | }; |
| 4860 | unsigned long now = jiffies; |
| 4861 | int status; |
| 4862 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4863 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | if (status < 0) |
| 4865 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4866 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | return 0; |
| 4868 | } |
| 4869 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4870 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4871 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4872 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4875 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4876 | * 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] | 4877 | * the stack. |
| 4878 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4879 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4880 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4881 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4882 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4883 | { |
| 4884 | struct page *newpage, **spages; |
| 4885 | int rc = 0; |
| 4886 | size_t len; |
| 4887 | spages = pages; |
| 4888 | |
| 4889 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4890 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4891 | newpage = alloc_page(GFP_KERNEL); |
| 4892 | |
| 4893 | if (newpage == NULL) |
| 4894 | goto unwind; |
| 4895 | memcpy(page_address(newpage), buf, len); |
| 4896 | buf += len; |
| 4897 | buflen -= len; |
| 4898 | *pages++ = newpage; |
| 4899 | rc++; |
| 4900 | } while (buflen != 0); |
| 4901 | |
| 4902 | return rc; |
| 4903 | |
| 4904 | unwind: |
| 4905 | for(; rc > 0; rc--) |
| 4906 | __free_page(spages[rc-1]); |
| 4907 | return -ENOMEM; |
| 4908 | } |
| 4909 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4910 | struct nfs4_cached_acl { |
| 4911 | int cached; |
| 4912 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4913 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4914 | }; |
| 4915 | |
| 4916 | 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] | 4917 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4918 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4919 | |
| 4920 | spin_lock(&inode->i_lock); |
| 4921 | kfree(nfsi->nfs4_acl); |
| 4922 | nfsi->nfs4_acl = acl; |
| 4923 | spin_unlock(&inode->i_lock); |
| 4924 | } |
| 4925 | |
| 4926 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4927 | { |
| 4928 | nfs4_set_cached_acl(inode, NULL); |
| 4929 | } |
| 4930 | |
| 4931 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4932 | { |
| 4933 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4934 | struct nfs4_cached_acl *acl; |
| 4935 | int ret = -ENOENT; |
| 4936 | |
| 4937 | spin_lock(&inode->i_lock); |
| 4938 | acl = nfsi->nfs4_acl; |
| 4939 | if (acl == NULL) |
| 4940 | goto out; |
| 4941 | if (buf == NULL) /* user is just asking for length */ |
| 4942 | goto out_len; |
| 4943 | if (acl->cached == 0) |
| 4944 | goto out; |
| 4945 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4946 | if (acl->len > buflen) |
| 4947 | goto out; |
| 4948 | memcpy(buf, acl->data, acl->len); |
| 4949 | out_len: |
| 4950 | ret = acl->len; |
| 4951 | out: |
| 4952 | spin_unlock(&inode->i_lock); |
| 4953 | return ret; |
| 4954 | } |
| 4955 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4956 | 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] | 4957 | { |
| 4958 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4959 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4960 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4961 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4962 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4963 | if (acl == NULL) |
| 4964 | goto out; |
| 4965 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4966 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4967 | } else { |
| 4968 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4969 | if (acl == NULL) |
| 4970 | goto out; |
| 4971 | acl->cached = 0; |
| 4972 | } |
| 4973 | acl->len = acl_len; |
| 4974 | out: |
| 4975 | nfs4_set_cached_acl(inode, acl); |
| 4976 | } |
| 4977 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4978 | /* |
| 4979 | * The getxattr API returns the required buffer length when called with a |
| 4980 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4981 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4982 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4983 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4984 | * the cache. If not so, we throw away the page, and cache the required |
| 4985 | * length. The next getxattr call will then produce another round trip to |
| 4986 | * the server, this time with the input buf of the required size. |
| 4987 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4988 | 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] | 4989 | { |
Weston Andros Adamson | d78f933 | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 4990 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4991 | struct nfs_getaclargs args = { |
| 4992 | .fh = NFS_FH(inode), |
| 4993 | .acl_pages = pages, |
| 4994 | .acl_len = buflen, |
| 4995 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4996 | struct nfs_getaclres res = { |
| 4997 | .acl_len = buflen, |
| 4998 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4999 | struct rpc_message msg = { |
| 5000 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5001 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5002 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5003 | }; |
Weston Andros Adamson | d78f933 | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5004 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5005 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5006 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5007 | if (npages > ARRAY_SIZE(pages)) |
| 5008 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5009 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5010 | for (i = 0; i < npages; i++) { |
| 5011 | pages[i] = alloc_page(GFP_KERNEL); |
| 5012 | if (!pages[i]) |
| 5013 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5014 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5015 | |
| 5016 | /* for decoding across pages */ |
| 5017 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5018 | if (!res.acl_scratch) |
| 5019 | goto out_free; |
| 5020 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5021 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5022 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5023 | 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] | 5024 | __func__, buf, buflen, npages, args.acl_len); |
| 5025 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5026 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5027 | if (ret) |
| 5028 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5029 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5030 | /* Handle the case where the passed-in buffer is too short */ |
| 5031 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5032 | /* Did the user only issue a request for the acl length? */ |
| 5033 | if (buf == NULL) |
| 5034 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5035 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5036 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5037 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5038 | 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] | 5039 | if (buf) { |
| 5040 | if (res.acl_len > buflen) { |
| 5041 | ret = -ERANGE; |
| 5042 | goto out_free; |
| 5043 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5044 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5045 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5046 | out_ok: |
| 5047 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5048 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5049 | for (i = 0; i < npages; i++) |
| 5050 | if (pages[i]) |
| 5051 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5052 | if (res.acl_scratch) |
| 5053 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5054 | return ret; |
| 5055 | } |
| 5056 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5057 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5058 | { |
| 5059 | struct nfs4_exception exception = { }; |
| 5060 | ssize_t ret; |
| 5061 | do { |
| 5062 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5063 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5064 | if (ret >= 0) |
| 5065 | break; |
| 5066 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5067 | } while (exception.retry); |
| 5068 | return ret; |
| 5069 | } |
| 5070 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5071 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5072 | { |
| 5073 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5074 | int ret; |
| 5075 | |
| 5076 | if (!nfs4_server_supports_acls(server)) |
| 5077 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5078 | ret = nfs_revalidate_inode(server, inode); |
| 5079 | if (ret < 0) |
| 5080 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5081 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5082 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5083 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5084 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5085 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5086 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5087 | return ret; |
| 5088 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5091 | 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] | 5092 | { |
| 5093 | struct nfs_server *server = NFS_SERVER(inode); |
| 5094 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5095 | struct nfs_setaclargs arg = { |
| 5096 | .fh = NFS_FH(inode), |
| 5097 | .acl_pages = pages, |
| 5098 | .acl_len = buflen, |
| 5099 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5100 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5101 | struct rpc_message msg = { |
| 5102 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5103 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5104 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5105 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5106 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5107 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5108 | |
| 5109 | if (!nfs4_server_supports_acls(server)) |
| 5110 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5111 | if (npages > ARRAY_SIZE(pages)) |
| 5112 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5113 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5114 | if (i < 0) |
| 5115 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5116 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5117 | 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] | 5118 | |
| 5119 | /* |
| 5120 | * Free each page after tx, so the only ref left is |
| 5121 | * held by the network stack |
| 5122 | */ |
| 5123 | for (; i > 0; i--) |
| 5124 | put_page(pages[i-1]); |
| 5125 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5126 | /* |
| 5127 | * Acl update can result in inode attribute update. |
| 5128 | * so mark the attribute cache invalid. |
| 5129 | */ |
| 5130 | spin_lock(&inode->i_lock); |
| 5131 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5132 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5133 | nfs_access_zap_cache(inode); |
| 5134 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5135 | return ret; |
| 5136 | } |
| 5137 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5138 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5139 | { |
| 5140 | struct nfs4_exception exception = { }; |
| 5141 | int err; |
| 5142 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5143 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5144 | trace_nfs4_set_acl(inode, err); |
| 5145 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5146 | &exception); |
| 5147 | } while (exception.retry); |
| 5148 | return err; |
| 5149 | } |
| 5150 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5151 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5152 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5153 | size_t buflen) |
| 5154 | { |
| 5155 | struct nfs_server *server = NFS_SERVER(inode); |
| 5156 | struct nfs_fattr fattr; |
| 5157 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5158 | |
| 5159 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5160 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5161 | .fh = NFS_FH(inode), |
| 5162 | .bitmask = bitmask, |
| 5163 | }; |
| 5164 | struct nfs4_getattr_res res = { |
| 5165 | .fattr = &fattr, |
| 5166 | .label = &label, |
| 5167 | .server = server, |
| 5168 | }; |
| 5169 | struct rpc_message msg = { |
| 5170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5171 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5172 | .rpc_resp = &res, |
| 5173 | }; |
| 5174 | int ret; |
| 5175 | |
| 5176 | nfs_fattr_init(&fattr); |
| 5177 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5178 | 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] | 5179 | if (ret) |
| 5180 | return ret; |
| 5181 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5182 | return -ENOENT; |
| 5183 | if (buflen < label.len) |
| 5184 | return -ERANGE; |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
| 5188 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5189 | size_t buflen) |
| 5190 | { |
| 5191 | struct nfs4_exception exception = { }; |
| 5192 | int err; |
| 5193 | |
| 5194 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5195 | return -EOPNOTSUPP; |
| 5196 | |
| 5197 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5198 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5199 | trace_nfs4_get_security_label(inode, err); |
| 5200 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5201 | &exception); |
| 5202 | } while (exception.retry); |
| 5203 | return err; |
| 5204 | } |
| 5205 | |
| 5206 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5207 | struct nfs4_label *ilabel, |
| 5208 | struct nfs_fattr *fattr, |
| 5209 | struct nfs4_label *olabel) |
| 5210 | { |
| 5211 | |
| 5212 | struct iattr sattr = {0}; |
| 5213 | struct nfs_server *server = NFS_SERVER(inode); |
| 5214 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5215 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5216 | .fh = NFS_FH(inode), |
| 5217 | .iap = &sattr, |
| 5218 | .server = server, |
| 5219 | .bitmask = bitmask, |
| 5220 | .label = ilabel, |
| 5221 | }; |
| 5222 | struct nfs_setattrres res = { |
| 5223 | .fattr = fattr, |
| 5224 | .label = olabel, |
| 5225 | .server = server, |
| 5226 | }; |
| 5227 | struct rpc_message msg = { |
| 5228 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5229 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5230 | .rpc_resp = &res, |
| 5231 | }; |
| 5232 | int status; |
| 5233 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5234 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5235 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5236 | 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] | 5237 | if (status) |
| 5238 | dprintk("%s failed: %d\n", __func__, status); |
| 5239 | |
| 5240 | return status; |
| 5241 | } |
| 5242 | |
| 5243 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5244 | struct nfs4_label *ilabel, |
| 5245 | struct nfs_fattr *fattr, |
| 5246 | struct nfs4_label *olabel) |
| 5247 | { |
| 5248 | struct nfs4_exception exception = { }; |
| 5249 | int err; |
| 5250 | |
| 5251 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5252 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5253 | fattr, olabel); |
| 5254 | trace_nfs4_set_security_label(inode, err); |
| 5255 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5256 | &exception); |
| 5257 | } while (exception.retry); |
| 5258 | return err; |
| 5259 | } |
| 5260 | |
| 5261 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5262 | 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] | 5263 | { |
| 5264 | struct nfs4_label ilabel, *olabel = NULL; |
| 5265 | struct nfs_fattr fattr; |
| 5266 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5267 | int status; |
| 5268 | |
| 5269 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5270 | return -EOPNOTSUPP; |
| 5271 | |
| 5272 | nfs_fattr_init(&fattr); |
| 5273 | |
| 5274 | ilabel.pi = 0; |
| 5275 | ilabel.lfs = 0; |
| 5276 | ilabel.label = (char *)buf; |
| 5277 | ilabel.len = buflen; |
| 5278 | |
| 5279 | cred = rpc_lookup_cred(); |
| 5280 | if (IS_ERR(cred)) |
| 5281 | return PTR_ERR(cred); |
| 5282 | |
| 5283 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5284 | if (IS_ERR(olabel)) { |
| 5285 | status = -PTR_ERR(olabel); |
| 5286 | goto out; |
| 5287 | } |
| 5288 | |
| 5289 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5290 | if (status == 0) |
| 5291 | nfs_setsecurity(inode, &fattr, olabel); |
| 5292 | |
| 5293 | nfs4_label_free(olabel); |
| 5294 | out: |
| 5295 | put_rpccred(cred); |
| 5296 | return status; |
| 5297 | } |
| 5298 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5299 | |
| 5300 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5301 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5302 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5303 | { |
| 5304 | __be32 verf[2]; |
| 5305 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5306 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5307 | /* An impossible timestamp guarantees this value |
| 5308 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5309 | verf[0] = cpu_to_be32(U32_MAX); |
| 5310 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5311 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5312 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5313 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5314 | |
| 5315 | verf[0] = cpu_to_be32(ns >> 32); |
| 5316 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5317 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5318 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5319 | } |
| 5320 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5321 | static int |
| 5322 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5323 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5324 | size_t len; |
| 5325 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5326 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5327 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5328 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5329 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5330 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5331 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5332 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5333 | 1 + |
| 5334 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5335 | 1; |
| 5336 | rcu_read_unlock(); |
| 5337 | |
| 5338 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5339 | return -EINVAL; |
| 5340 | |
| 5341 | /* |
| 5342 | * Since this string is allocated at mount time, and held until the |
| 5343 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5344 | * about a memory-reclaim deadlock. |
| 5345 | */ |
| 5346 | str = kmalloc(len, GFP_KERNEL); |
| 5347 | if (!str) |
| 5348 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5349 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5350 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5351 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5352 | clp->cl_ipaddr, |
| 5353 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5354 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5355 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5356 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5357 | clp->cl_owner_id = str; |
| 5358 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5359 | } |
| 5360 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5361 | static int |
| 5362 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5363 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5364 | size_t len; |
| 5365 | char *str; |
| 5366 | |
| 5367 | len = 10 + 10 + 1 + 10 + 1 + |
| 5368 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5369 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5370 | |
| 5371 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5372 | return -EINVAL; |
| 5373 | |
| 5374 | /* |
| 5375 | * Since this string is allocated at mount time, and held until the |
| 5376 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5377 | * about a memory-reclaim deadlock. |
| 5378 | */ |
| 5379 | str = kmalloc(len, GFP_KERNEL); |
| 5380 | if (!str) |
| 5381 | return -ENOMEM; |
| 5382 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5383 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5384 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5385 | nfs4_client_id_uniquifier, |
| 5386 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5387 | clp->cl_owner_id = str; |
| 5388 | return 0; |
| 5389 | } |
| 5390 | |
| 5391 | static int |
| 5392 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5393 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5394 | size_t len; |
| 5395 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5396 | |
| 5397 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5398 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5399 | |
| 5400 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5401 | return nfs4_init_uniquifier_client_string(clp); |
| 5402 | |
| 5403 | len = 10 + 10 + 1 + 10 + 1 + |
| 5404 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5405 | |
| 5406 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5407 | return -EINVAL; |
| 5408 | |
| 5409 | /* |
| 5410 | * Since this string is allocated at mount time, and held until the |
| 5411 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5412 | * about a memory-reclaim deadlock. |
| 5413 | */ |
| 5414 | str = kmalloc(len, GFP_KERNEL); |
| 5415 | if (!str) |
| 5416 | return -ENOMEM; |
| 5417 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5418 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5419 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5420 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5421 | clp->cl_owner_id = str; |
| 5422 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5423 | } |
| 5424 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5425 | /* |
| 5426 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5427 | * services. Advertise one based on the address family of the |
| 5428 | * clientaddr. |
| 5429 | */ |
| 5430 | static unsigned int |
| 5431 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5432 | { |
| 5433 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5434 | return scnprintf(buf, len, "tcp6"); |
| 5435 | else |
| 5436 | return scnprintf(buf, len, "tcp"); |
| 5437 | } |
| 5438 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5439 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5440 | { |
| 5441 | struct nfs4_setclientid *sc = calldata; |
| 5442 | |
| 5443 | if (task->tk_status == 0) |
| 5444 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5445 | } |
| 5446 | |
| 5447 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5448 | .rpc_call_done = nfs4_setclientid_done, |
| 5449 | }; |
| 5450 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5451 | /** |
| 5452 | * nfs4_proc_setclientid - Negotiate client ID |
| 5453 | * @clp: state data structure |
| 5454 | * @program: RPC program for NFSv4 callback service |
| 5455 | * @port: IP port number for NFS4 callback service |
| 5456 | * @cred: RPC credential to use for this call |
| 5457 | * @res: where to place the result |
| 5458 | * |
| 5459 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5460 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5461 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5462 | unsigned short port, struct rpc_cred *cred, |
| 5463 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | { |
| 5465 | nfs4_verifier sc_verifier; |
| 5466 | struct nfs4_setclientid setclientid = { |
| 5467 | .sc_verifier = &sc_verifier, |
| 5468 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5469 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | }; |
| 5471 | struct rpc_message msg = { |
| 5472 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5473 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5474 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5475 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5477 | struct rpc_task *task; |
| 5478 | struct rpc_task_setup task_setup_data = { |
| 5479 | .rpc_client = clp->cl_rpcclient, |
| 5480 | .rpc_message = &msg, |
| 5481 | .callback_ops = &nfs4_setclientid_ops, |
| 5482 | .callback_data = &setclientid, |
| 5483 | .flags = RPC_TASK_TIMEOUT, |
| 5484 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5485 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5487 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5488 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5489 | |
| 5490 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5491 | status = nfs4_init_uniform_client_string(clp); |
| 5492 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5493 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5494 | |
| 5495 | if (status) |
| 5496 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5497 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5498 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5499 | setclientid.sc_netid_len = |
| 5500 | nfs4_init_callback_netid(clp, |
| 5501 | setclientid.sc_netid, |
| 5502 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5503 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5504 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5506 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5507 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5508 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5509 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5510 | task = rpc_run_task(&task_setup_data); |
| 5511 | if (IS_ERR(task)) { |
| 5512 | status = PTR_ERR(task); |
| 5513 | goto out; |
| 5514 | } |
| 5515 | status = task->tk_status; |
| 5516 | if (setclientid.sc_cred) { |
| 5517 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5518 | put_rpccred(setclientid.sc_cred); |
| 5519 | } |
| 5520 | rpc_put_task(task); |
| 5521 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5522 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5523 | dprintk("NFS reply setclientid: %d\n", status); |
| 5524 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5527 | /** |
| 5528 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5529 | * @clp: state data structure |
| 5530 | * @res: result of a previous SETCLIENTID |
| 5531 | * @cred: RPC credential to use for this call |
| 5532 | * |
| 5533 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5534 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5535 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5536 | struct nfs4_setclientid_res *arg, |
| 5537 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | struct rpc_message msg = { |
| 5540 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5541 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5542 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | int status; |
| 5545 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5546 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5547 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5548 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5549 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5550 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5551 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | return status; |
| 5553 | } |
| 5554 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5555 | struct nfs4_delegreturndata { |
| 5556 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5557 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5558 | struct nfs_fh fh; |
| 5559 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5560 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5561 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5562 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5563 | struct inode *inode; |
| 5564 | bool roc; |
| 5565 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5566 | }; |
| 5567 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5568 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5569 | { |
| 5570 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5571 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5572 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5573 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5574 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5575 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5576 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5577 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5578 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5579 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5580 | case -NFS4ERR_ADMIN_REVOKED: |
| 5581 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5582 | case -NFS4ERR_EXPIRED: |
| 5583 | nfs4_free_revoked_stateid(data->res.server, |
| 5584 | data->args.stateid, |
| 5585 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5586 | case -NFS4ERR_BAD_STATEID: |
| 5587 | case -NFS4ERR_OLD_STATEID: |
| 5588 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5589 | task->tk_status = 0; |
| 5590 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5591 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5592 | if (nfs4_async_handle_error(task, data->res.server, |
| 5593 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5594 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5595 | return; |
| 5596 | } |
| 5597 | } |
| 5598 | data->rpc_status = task->tk_status; |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5599 | if (data->roc && data->rpc_status == 0) |
| 5600 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | static void nfs4_delegreturn_release(void *calldata) |
| 5604 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5605 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5606 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5607 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5608 | if (inode) { |
| 5609 | if (data->roc) |
| 5610 | pnfs_roc_release(inode); |
| 5611 | nfs_iput_and_deactive(inode); |
| 5612 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5613 | kfree(calldata); |
| 5614 | } |
| 5615 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5616 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5617 | { |
| 5618 | struct nfs4_delegreturndata *d_data; |
| 5619 | |
| 5620 | d_data = (struct nfs4_delegreturndata *)data; |
| 5621 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5622 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5623 | return; |
| 5624 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5625 | if (d_data->roc) |
| 5626 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5627 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5628 | nfs4_setup_sequence(d_data->res.server, |
| 5629 | &d_data->args.seq_args, |
| 5630 | &d_data->res.seq_res, |
| 5631 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5632 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5633 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5634 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5635 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5636 | .rpc_call_done = nfs4_delegreturn_done, |
| 5637 | .rpc_release = nfs4_delegreturn_release, |
| 5638 | }; |
| 5639 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5640 | 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] | 5641 | { |
| 5642 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5643 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5644 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5645 | struct rpc_message msg = { |
| 5646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5647 | .rpc_cred = cred, |
| 5648 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5649 | struct rpc_task_setup task_setup_data = { |
| 5650 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5651 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5652 | .callback_ops = &nfs4_delegreturn_ops, |
| 5653 | .flags = RPC_TASK_ASYNC, |
| 5654 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5655 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5656 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5657 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5658 | if (data == NULL) |
| 5659 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5660 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5661 | |
| 5662 | nfs4_state_protect(server->nfs_client, |
| 5663 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5664 | &task_setup_data.rpc_client, &msg); |
| 5665 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5666 | data->args.fhandle = &data->fh; |
| 5667 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5668 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5669 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5670 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5671 | data->res.fattr = &data->fattr; |
| 5672 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5673 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5674 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5675 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5676 | data->inode = nfs_igrab_and_active(inode); |
| 5677 | if (data->inode) |
| 5678 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5679 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5680 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5681 | msg.rpc_argp = &data->args; |
| 5682 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5683 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5684 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5685 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5686 | if (!issync) |
| 5687 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5688 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5689 | if (status != 0) |
| 5690 | goto out; |
| 5691 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5692 | if (status == 0) |
| 5693 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5694 | else |
| 5695 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5696 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5697 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5698 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | } |
| 5700 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5701 | 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] | 5702 | { |
| 5703 | struct nfs_server *server = NFS_SERVER(inode); |
| 5704 | struct nfs4_exception exception = { }; |
| 5705 | int err; |
| 5706 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5707 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5708 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | switch (err) { |
| 5710 | case -NFS4ERR_STALE_STATEID: |
| 5711 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | case 0: |
| 5713 | return 0; |
| 5714 | } |
| 5715 | err = nfs4_handle_exception(server, err, &exception); |
| 5716 | } while (exception.retry); |
| 5717 | return err; |
| 5718 | } |
| 5719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5721 | { |
| 5722 | struct inode *inode = state->inode; |
| 5723 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5724 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5725 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5727 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5729 | struct nfs_lockt_res res = { |
| 5730 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | }; |
| 5732 | struct rpc_message msg = { |
| 5733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5734 | .rpc_argp = &arg, |
| 5735 | .rpc_resp = &res, |
| 5736 | .rpc_cred = state->owner->so_cred, |
| 5737 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | struct nfs4_lock_state *lsp; |
| 5739 | int status; |
| 5740 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5741 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5742 | status = nfs4_set_lock_state(state, request); |
| 5743 | if (status != 0) |
| 5744 | goto out; |
| 5745 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5746 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5747 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5748 | 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] | 5749 | switch (status) { |
| 5750 | case 0: |
| 5751 | request->fl_type = F_UNLCK; |
| 5752 | break; |
| 5753 | case -NFS4ERR_DENIED: |
| 5754 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5756 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5757 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5758 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | return status; |
| 5760 | } |
| 5761 | |
| 5762 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5763 | { |
| 5764 | struct nfs4_exception exception = { }; |
| 5765 | int err; |
| 5766 | |
| 5767 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5768 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5769 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5770 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | &exception); |
| 5772 | } while (exception.retry); |
| 5773 | return err; |
| 5774 | } |
| 5775 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5776 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5777 | struct nfs_locku_args arg; |
| 5778 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5779 | struct nfs4_lock_state *lsp; |
| 5780 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5781 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5782 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5783 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5784 | }; |
| 5785 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5786 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5787 | struct nfs_open_context *ctx, |
| 5788 | struct nfs4_lock_state *lsp, |
| 5789 | struct nfs_seqid *seqid) |
| 5790 | { |
| 5791 | struct nfs4_unlockdata *p; |
| 5792 | struct inode *inode = lsp->ls_state->inode; |
| 5793 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5794 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5795 | if (p == NULL) |
| 5796 | return NULL; |
| 5797 | p->arg.fh = NFS_FH(inode); |
| 5798 | p->arg.fl = &p->fl; |
| 5799 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5800 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5801 | p->lsp = lsp; |
| 5802 | atomic_inc(&lsp->ls_count); |
| 5803 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5804 | p->ctx = get_nfs_open_context(ctx); |
| 5805 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5806 | p->server = NFS_SERVER(inode); |
| 5807 | return p; |
| 5808 | } |
| 5809 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5810 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5811 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5812 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5813 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5814 | nfs4_put_lock_state(calldata->lsp); |
| 5815 | put_nfs_open_context(calldata->ctx); |
| 5816 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5819 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5820 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5821 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5822 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5823 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5824 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5825 | switch (task->tk_status) { |
| 5826 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5827 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5828 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5829 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5830 | &calldata->res.stateid)) |
| 5831 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5832 | case -NFS4ERR_ADMIN_REVOKED: |
| 5833 | case -NFS4ERR_EXPIRED: |
| 5834 | nfs4_free_revoked_stateid(calldata->server, |
| 5835 | &calldata->arg.stateid, |
| 5836 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5837 | case -NFS4ERR_BAD_STATEID: |
| 5838 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5839 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5840 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5841 | &calldata->lsp->ls_stateid)) |
| 5842 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5843 | break; |
| 5844 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5845 | if (nfs4_async_handle_error(task, calldata->server, |
| 5846 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5847 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5848 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5849 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5852 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5853 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5854 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5856 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5857 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5858 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5859 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5860 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5861 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5862 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5863 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5864 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5865 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5866 | &calldata->res.seq_res, |
| 5867 | task) != 0) |
| 5868 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5869 | return; |
| 5870 | out_no_action: |
| 5871 | task->tk_action = NULL; |
| 5872 | out_wait: |
| 5873 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5874 | } |
| 5875 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5876 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5877 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5878 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5879 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5880 | }; |
| 5881 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5882 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5883 | struct nfs_open_context *ctx, |
| 5884 | struct nfs4_lock_state *lsp, |
| 5885 | struct nfs_seqid *seqid) |
| 5886 | { |
| 5887 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5888 | struct rpc_message msg = { |
| 5889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5890 | .rpc_cred = ctx->cred, |
| 5891 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5892 | struct rpc_task_setup task_setup_data = { |
| 5893 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5894 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5895 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5896 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5897 | .flags = RPC_TASK_ASYNC, |
| 5898 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5899 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5900 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5901 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5902 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5903 | /* Ensure this is an unlock - when canceling a lock, the |
| 5904 | * canceled lock is passed in, and it won't be an unlock. |
| 5905 | */ |
| 5906 | fl->fl_type = F_UNLCK; |
| 5907 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5908 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5909 | if (data == NULL) { |
| 5910 | nfs_free_seqid(seqid); |
| 5911 | return ERR_PTR(-ENOMEM); |
| 5912 | } |
| 5913 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5914 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5915 | msg.rpc_argp = &data->arg; |
| 5916 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5917 | task_setup_data.callback_data = data; |
| 5918 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5919 | } |
| 5920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5921 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5922 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5923 | struct inode *inode = state->inode; |
| 5924 | struct nfs4_state_owner *sp = state->owner; |
| 5925 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5926 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5927 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5928 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5929 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5930 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5931 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5933 | status = nfs4_set_lock_state(state, request); |
| 5934 | /* Unlock _before_ we do the RPC call */ |
| 5935 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5936 | /* Exclude nfs_delegation_claim_locks() */ |
| 5937 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5938 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5939 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5940 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5941 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5942 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5943 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5944 | } |
| 5945 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5946 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5947 | if (status != 0) |
| 5948 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5949 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5950 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5951 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5952 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5953 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5954 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5955 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5956 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5957 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5958 | 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] | 5959 | status = PTR_ERR(task); |
| 5960 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5961 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5962 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5963 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5964 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5965 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5966 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5967 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5970 | struct nfs4_lockdata { |
| 5971 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5972 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5973 | struct nfs4_lock_state *lsp; |
| 5974 | struct nfs_open_context *ctx; |
| 5975 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5976 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5977 | int rpc_status; |
| 5978 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5979 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5983 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5984 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5985 | { |
| 5986 | struct nfs4_lockdata *p; |
| 5987 | struct inode *inode = lsp->ls_state->inode; |
| 5988 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5989 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5990 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5991 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5992 | if (p == NULL) |
| 5993 | return NULL; |
| 5994 | |
| 5995 | p->arg.fh = NFS_FH(inode); |
| 5996 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5997 | 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] | 5998 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5999 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6000 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6001 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6002 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6003 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6004 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6005 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6006 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6007 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6008 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6009 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6010 | atomic_inc(&lsp->ls_count); |
| 6011 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6012 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6013 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6014 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6015 | out_free_seqid: |
| 6016 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6017 | out_free: |
| 6018 | kfree(p); |
| 6019 | return NULL; |
| 6020 | } |
| 6021 | |
| 6022 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6023 | { |
| 6024 | struct nfs4_lockdata *data = calldata; |
| 6025 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6026 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6027 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6028 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6029 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6030 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6031 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6032 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6033 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6034 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6035 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6036 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6037 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6038 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6039 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6040 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6041 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6042 | &data->lsp->ls_stateid); |
| 6043 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6044 | if (!nfs4_valid_open_stateid(state)) { |
| 6045 | data->rpc_status = -EBADF; |
| 6046 | task->tk_action = NULL; |
| 6047 | goto out_release_open_seqid; |
| 6048 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6049 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6050 | if (nfs4_setup_sequence(data->server, |
| 6051 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6052 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6053 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6054 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6055 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6056 | nfs_release_seqid(data->arg.open_seqid); |
| 6057 | out_release_lock_seqid: |
| 6058 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6059 | out_wait: |
| 6060 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6061 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6062 | } |
| 6063 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6064 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6065 | { |
| 6066 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6067 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6068 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6069 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6070 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6071 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6072 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6073 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6074 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6075 | switch (task->tk_status) { |
| 6076 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6077 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6078 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6079 | if (data->arg.new_lock) { |
| 6080 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6081 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6082 | rpc_restart_call_prepare(task); |
| 6083 | break; |
| 6084 | } |
| 6085 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6086 | if (data->arg.new_lock_owner != 0) { |
| 6087 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6088 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6089 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6090 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6091 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6092 | break; |
| 6093 | case -NFS4ERR_BAD_STATEID: |
| 6094 | case -NFS4ERR_OLD_STATEID: |
| 6095 | case -NFS4ERR_STALE_STATEID: |
| 6096 | case -NFS4ERR_EXPIRED: |
| 6097 | if (data->arg.new_lock_owner != 0) { |
| 6098 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6099 | &lsp->ls_state->open_stateid)) |
| 6100 | rpc_restart_call_prepare(task); |
| 6101 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6102 | &lsp->ls_stateid)) |
| 6103 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6104 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6105 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | static void nfs4_lock_release(void *calldata) |
| 6109 | { |
| 6110 | struct nfs4_lockdata *data = calldata; |
| 6111 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6112 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6113 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6114 | if (data->cancelled != 0) { |
| 6115 | struct rpc_task *task; |
| 6116 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6117 | data->arg.lock_seqid); |
| 6118 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6119 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6120 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6121 | } else |
| 6122 | nfs_free_seqid(data->arg.lock_seqid); |
| 6123 | nfs4_put_lock_state(data->lsp); |
| 6124 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6125 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6126 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6127 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6131 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6132 | .rpc_call_done = nfs4_lock_done, |
| 6133 | .rpc_release = nfs4_lock_release, |
| 6134 | }; |
| 6135 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6136 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6137 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6138 | switch (error) { |
| 6139 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6140 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6141 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6142 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6143 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6144 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6145 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6146 | break; |
| 6147 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6148 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6149 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6150 | }; |
| 6151 | } |
| 6152 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6153 | 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] | 6154 | { |
| 6155 | struct nfs4_lockdata *data; |
| 6156 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6157 | struct rpc_message msg = { |
| 6158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6159 | .rpc_cred = state->owner->so_cred, |
| 6160 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6161 | struct rpc_task_setup task_setup_data = { |
| 6162 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6163 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6164 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6165 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6166 | .flags = RPC_TASK_ASYNC, |
| 6167 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6168 | int ret; |
| 6169 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6170 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6171 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6172 | fl->fl_u.nfs4_fl.owner, |
| 6173 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6174 | if (data == NULL) |
| 6175 | return -ENOMEM; |
| 6176 | if (IS_SETLKW(cmd)) |
| 6177 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6178 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6179 | msg.rpc_argp = &data->arg; |
| 6180 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6181 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6182 | if (recovery_type > NFS_LOCK_NEW) { |
| 6183 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6184 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6185 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6186 | } else |
| 6187 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6188 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6189 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6190 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6191 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6192 | if (ret == 0) { |
| 6193 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6194 | if (ret) |
| 6195 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6196 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6197 | } else |
| 6198 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6199 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6200 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6201 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6202 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6206 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6207 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6208 | struct nfs4_exception exception = { |
| 6209 | .inode = state->inode, |
| 6210 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6211 | int err; |
| 6212 | |
| 6213 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6214 | /* Cache the lock if possible... */ |
| 6215 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6216 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6217 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6218 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6219 | break; |
| 6220 | nfs4_handle_exception(server, err, &exception); |
| 6221 | } while (exception.retry); |
| 6222 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6226 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6227 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6228 | struct nfs4_exception exception = { |
| 6229 | .inode = state->inode, |
| 6230 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6231 | int err; |
| 6232 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6233 | err = nfs4_set_lock_state(state, request); |
| 6234 | if (err != 0) |
| 6235 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6236 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6237 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6238 | return 0; |
| 6239 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6240 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6241 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6242 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6243 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6244 | switch (err) { |
| 6245 | default: |
| 6246 | goto out; |
| 6247 | case -NFS4ERR_GRACE: |
| 6248 | case -NFS4ERR_DELAY: |
| 6249 | nfs4_handle_exception(server, err, &exception); |
| 6250 | err = 0; |
| 6251 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6252 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6253 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6254 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | } |
| 6256 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6257 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6258 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6259 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6260 | struct nfs4_lock_state *lsp; |
| 6261 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6262 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6263 | status = nfs4_set_lock_state(state, request); |
| 6264 | if (status != 0) |
| 6265 | return status; |
| 6266 | lsp = request->fl_u.nfs4_fl.owner; |
| 6267 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6268 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6269 | return 0; |
| 6270 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6271 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6272 | } |
| 6273 | #endif |
| 6274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6276 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6277 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6278 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6279 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6280 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6282 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6283 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6284 | if (status < 0) |
| 6285 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6286 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6287 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6288 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6289 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6290 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6291 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6292 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6293 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6294 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6295 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6296 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6297 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6298 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6299 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6300 | out: |
| 6301 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | return status; |
| 6303 | } |
| 6304 | |
| 6305 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6306 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6307 | struct nfs4_exception exception = { |
| 6308 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6309 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6310 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | int err; |
| 6312 | |
| 6313 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6314 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6315 | if (err == -NFS4ERR_DENIED) |
| 6316 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6318 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6319 | } while (exception.retry); |
| 6320 | return err; |
| 6321 | } |
| 6322 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6323 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6324 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6325 | |
| 6326 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6327 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6328 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6329 | { |
| 6330 | int status = -ERESTARTSYS; |
| 6331 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6332 | |
| 6333 | while(!signalled()) { |
| 6334 | status = nfs4_proc_setlk(state, cmd, request); |
| 6335 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6336 | break; |
| 6337 | freezable_schedule_timeout_interruptible(timeout); |
| 6338 | timeout *= 2; |
| 6339 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6340 | status = -ERESTARTSYS; |
| 6341 | } |
| 6342 | return status; |
| 6343 | } |
| 6344 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6345 | #ifdef CONFIG_NFS_V4_1 |
| 6346 | struct nfs4_lock_waiter { |
| 6347 | struct task_struct *task; |
| 6348 | struct inode *inode; |
| 6349 | struct nfs_lowner *owner; |
| 6350 | bool notified; |
| 6351 | }; |
| 6352 | |
| 6353 | static int |
| 6354 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6355 | { |
| 6356 | int ret; |
| 6357 | struct cb_notify_lock_args *cbnl = key; |
| 6358 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6359 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6360 | *wowner = waiter->owner; |
| 6361 | |
| 6362 | /* Only wake if the callback was for the same owner */ |
| 6363 | if (lowner->clientid != wowner->clientid || |
| 6364 | lowner->id != wowner->id || |
| 6365 | lowner->s_dev != wowner->s_dev) |
| 6366 | return 0; |
| 6367 | |
| 6368 | /* Make sure it's for the right inode */ |
| 6369 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6370 | return 0; |
| 6371 | |
| 6372 | waiter->notified = true; |
| 6373 | |
| 6374 | /* override "private" so we can use default_wake_function */ |
| 6375 | wait->private = waiter->task; |
| 6376 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6377 | wait->private = waiter; |
| 6378 | return ret; |
| 6379 | } |
| 6380 | |
| 6381 | static int |
| 6382 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6383 | { |
| 6384 | int status = -ERESTARTSYS; |
| 6385 | unsigned long flags; |
| 6386 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6387 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6388 | struct nfs_client *clp = server->nfs_client; |
| 6389 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6390 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6391 | .id = lsp->ls_seqid.owner_id, |
| 6392 | .s_dev = server->s_dev }; |
| 6393 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6394 | .inode = state->inode, |
| 6395 | .owner = &owner, |
| 6396 | .notified = false }; |
| 6397 | wait_queue_t wait; |
| 6398 | |
| 6399 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6400 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6401 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6402 | |
| 6403 | init_wait(&wait); |
| 6404 | wait.private = &waiter; |
| 6405 | wait.func = nfs4_wake_lock_waiter; |
| 6406 | add_wait_queue(q, &wait); |
| 6407 | |
| 6408 | while(!signalled()) { |
| 6409 | status = nfs4_proc_setlk(state, cmd, request); |
| 6410 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6411 | break; |
| 6412 | |
| 6413 | status = -ERESTARTSYS; |
| 6414 | spin_lock_irqsave(&q->lock, flags); |
| 6415 | if (waiter.notified) { |
| 6416 | spin_unlock_irqrestore(&q->lock, flags); |
| 6417 | continue; |
| 6418 | } |
| 6419 | set_current_state(TASK_INTERRUPTIBLE); |
| 6420 | spin_unlock_irqrestore(&q->lock, flags); |
| 6421 | |
| 6422 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6423 | } |
| 6424 | |
| 6425 | finish_wait(q, &wait); |
| 6426 | return status; |
| 6427 | } |
| 6428 | #else /* !CONFIG_NFS_V4_1 */ |
| 6429 | static inline int |
| 6430 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6431 | { |
| 6432 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6433 | } |
| 6434 | #endif |
| 6435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6436 | static int |
| 6437 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6438 | { |
| 6439 | struct nfs_open_context *ctx; |
| 6440 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6441 | int status; |
| 6442 | |
| 6443 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6444 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6445 | state = ctx->state; |
| 6446 | |
| 6447 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6448 | return -EINVAL; |
| 6449 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6450 | if (IS_GETLK(cmd)) { |
| 6451 | if (state != NULL) |
| 6452 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6453 | return 0; |
| 6454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | |
| 6456 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6457 | return -EINVAL; |
| 6458 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6459 | if (request->fl_type == F_UNLCK) { |
| 6460 | if (state != NULL) |
| 6461 | return nfs4_proc_unlck(state, cmd, request); |
| 6462 | return 0; |
| 6463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6464 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6465 | if (state == NULL) |
| 6466 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6467 | |
| 6468 | if ((request->fl_flags & FL_POSIX) && |
| 6469 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6470 | return -ENOLCK; |
| 6471 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6472 | /* |
| 6473 | * Don't rely on the VFS having checked the file open mode, |
| 6474 | * since it won't do this for flock() locks. |
| 6475 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6476 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6477 | case F_RDLCK: |
| 6478 | if (!(filp->f_mode & FMODE_READ)) |
| 6479 | return -EBADF; |
| 6480 | break; |
| 6481 | case F_WRLCK: |
| 6482 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6483 | return -EBADF; |
| 6484 | } |
| 6485 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6486 | status = nfs4_set_lock_state(state, request); |
| 6487 | if (status != 0) |
| 6488 | return status; |
| 6489 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6490 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6491 | } |
| 6492 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6493 | 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] | 6494 | { |
| 6495 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6496 | int err; |
| 6497 | |
| 6498 | err = nfs4_set_lock_state(state, fl); |
| 6499 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6500 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6501 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6502 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6503 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6504 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6505 | struct nfs_release_lockowner_data { |
| 6506 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6507 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6508 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6509 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6510 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6511 | }; |
| 6512 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6513 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6514 | { |
| 6515 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6516 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6517 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6518 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6519 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6520 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6521 | } |
| 6522 | |
| 6523 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6524 | { |
| 6525 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6526 | struct nfs_server *server = data->server; |
| 6527 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6528 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6529 | |
| 6530 | switch (task->tk_status) { |
| 6531 | case 0: |
| 6532 | renew_lease(server, data->timestamp); |
| 6533 | break; |
| 6534 | case -NFS4ERR_STALE_CLIENTID: |
| 6535 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6536 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6537 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6538 | case -NFS4ERR_LEASE_MOVED: |
| 6539 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6540 | if (nfs4_async_handle_error(task, server, |
| 6541 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6542 | rpc_restart_call_prepare(task); |
| 6543 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6544 | } |
| 6545 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6546 | static void nfs4_release_lockowner_release(void *calldata) |
| 6547 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6548 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6549 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6550 | kfree(calldata); |
| 6551 | } |
| 6552 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6553 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6554 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6555 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6556 | .rpc_release = nfs4_release_lockowner_release, |
| 6557 | }; |
| 6558 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6559 | static void |
| 6560 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6561 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6562 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6563 | struct rpc_message msg = { |
| 6564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6565 | }; |
| 6566 | |
| 6567 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6568 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6569 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6570 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6571 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6572 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6573 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6574 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6575 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6576 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6577 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6578 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6579 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6580 | msg.rpc_resp = &data->res; |
| 6581 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6582 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6583 | } |
| 6584 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6585 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6586 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6587 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6588 | struct dentry *unused, struct inode *inode, |
| 6589 | const char *key, const void *buf, |
| 6590 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6591 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6592 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6593 | } |
| 6594 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6595 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6596 | struct dentry *unused, struct inode *inode, |
| 6597 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6598 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6599 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6600 | } |
| 6601 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6602 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6603 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6604 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6607 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6608 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6609 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6610 | struct dentry *unused, struct inode *inode, |
| 6611 | const char *key, const void *buf, |
| 6612 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6613 | { |
| 6614 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6615 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6616 | |
| 6617 | return -EOPNOTSUPP; |
| 6618 | } |
| 6619 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6620 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6621 | struct dentry *unused, struct inode *inode, |
| 6622 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6623 | { |
| 6624 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6625 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6626 | return -EOPNOTSUPP; |
| 6627 | } |
| 6628 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6629 | static ssize_t |
| 6630 | 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] | 6631 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6632 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6633 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6634 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6635 | len = security_inode_listsecurity(inode, list, list_len); |
| 6636 | if (list_len && len > list_len) |
| 6637 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6638 | } |
| 6639 | return len; |
| 6640 | } |
| 6641 | |
| 6642 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6643 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6644 | .get = nfs4_xattr_get_nfs4_label, |
| 6645 | .set = nfs4_xattr_set_nfs4_label, |
| 6646 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6647 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6648 | #else |
| 6649 | |
| 6650 | static ssize_t |
| 6651 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6652 | { |
| 6653 | return 0; |
| 6654 | } |
| 6655 | |
| 6656 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6657 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6658 | /* |
| 6659 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6660 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6661 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6662 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6663 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6664 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6665 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6666 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6667 | return; |
| 6668 | |
| 6669 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6670 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6671 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6672 | fattr->nlink = 2; |
| 6673 | } |
| 6674 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6675 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6676 | const struct qstr *name, |
| 6677 | struct nfs4_fs_locations *fs_locations, |
| 6678 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6679 | { |
| 6680 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6681 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6682 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6683 | }; |
| 6684 | struct nfs4_fs_locations_arg args = { |
| 6685 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6686 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6687 | .page = page, |
| 6688 | .bitmask = bitmask, |
| 6689 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6690 | struct nfs4_fs_locations_res res = { |
| 6691 | .fs_locations = fs_locations, |
| 6692 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6693 | struct rpc_message msg = { |
| 6694 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6695 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6696 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6697 | }; |
| 6698 | int status; |
| 6699 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6700 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6701 | |
| 6702 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6703 | * is not supported */ |
| 6704 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6705 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6706 | else |
| 6707 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6708 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6709 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6710 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6711 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6712 | 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] | 6713 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6714 | return status; |
| 6715 | } |
| 6716 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6717 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6718 | const struct qstr *name, |
| 6719 | struct nfs4_fs_locations *fs_locations, |
| 6720 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6721 | { |
| 6722 | struct nfs4_exception exception = { }; |
| 6723 | int err; |
| 6724 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6725 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6726 | fs_locations, page); |
| 6727 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6728 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6729 | &exception); |
| 6730 | } while (exception.retry); |
| 6731 | return err; |
| 6732 | } |
| 6733 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6734 | /* |
| 6735 | * This operation also signals the server that this client is |
| 6736 | * performing migration recovery. The server can stop returning |
| 6737 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6738 | * appended to this compound to identify the client ID which is |
| 6739 | * performing recovery. |
| 6740 | */ |
| 6741 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6742 | struct nfs4_fs_locations *locations, |
| 6743 | struct page *page, struct rpc_cred *cred) |
| 6744 | { |
| 6745 | struct nfs_server *server = NFS_SERVER(inode); |
| 6746 | struct rpc_clnt *clnt = server->client; |
| 6747 | u32 bitmask[2] = { |
| 6748 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6749 | }; |
| 6750 | struct nfs4_fs_locations_arg args = { |
| 6751 | .clientid = server->nfs_client->cl_clientid, |
| 6752 | .fh = NFS_FH(inode), |
| 6753 | .page = page, |
| 6754 | .bitmask = bitmask, |
| 6755 | .migration = 1, /* skip LOOKUP */ |
| 6756 | .renew = 1, /* append RENEW */ |
| 6757 | }; |
| 6758 | struct nfs4_fs_locations_res res = { |
| 6759 | .fs_locations = locations, |
| 6760 | .migration = 1, |
| 6761 | .renew = 1, |
| 6762 | }; |
| 6763 | struct rpc_message msg = { |
| 6764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6765 | .rpc_argp = &args, |
| 6766 | .rpc_resp = &res, |
| 6767 | .rpc_cred = cred, |
| 6768 | }; |
| 6769 | unsigned long now = jiffies; |
| 6770 | int status; |
| 6771 | |
| 6772 | nfs_fattr_init(&locations->fattr); |
| 6773 | locations->server = server; |
| 6774 | locations->nlocations = 0; |
| 6775 | |
| 6776 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6777 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6778 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6779 | &args.seq_args, &res.seq_res); |
| 6780 | if (status) |
| 6781 | return status; |
| 6782 | |
| 6783 | renew_lease(server, now); |
| 6784 | return 0; |
| 6785 | } |
| 6786 | |
| 6787 | #ifdef CONFIG_NFS_V4_1 |
| 6788 | |
| 6789 | /* |
| 6790 | * This operation also signals the server that this client is |
| 6791 | * performing migration recovery. The server can stop asserting |
| 6792 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6793 | * performing this operation is identified in the SEQUENCE |
| 6794 | * operation in this compound. |
| 6795 | * |
| 6796 | * When the client supports GETATTR(fs_locations_info), it can |
| 6797 | * be plumbed in here. |
| 6798 | */ |
| 6799 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6800 | struct nfs4_fs_locations *locations, |
| 6801 | struct page *page, struct rpc_cred *cred) |
| 6802 | { |
| 6803 | struct nfs_server *server = NFS_SERVER(inode); |
| 6804 | struct rpc_clnt *clnt = server->client; |
| 6805 | u32 bitmask[2] = { |
| 6806 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6807 | }; |
| 6808 | struct nfs4_fs_locations_arg args = { |
| 6809 | .fh = NFS_FH(inode), |
| 6810 | .page = page, |
| 6811 | .bitmask = bitmask, |
| 6812 | .migration = 1, /* skip LOOKUP */ |
| 6813 | }; |
| 6814 | struct nfs4_fs_locations_res res = { |
| 6815 | .fs_locations = locations, |
| 6816 | .migration = 1, |
| 6817 | }; |
| 6818 | struct rpc_message msg = { |
| 6819 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6820 | .rpc_argp = &args, |
| 6821 | .rpc_resp = &res, |
| 6822 | .rpc_cred = cred, |
| 6823 | }; |
| 6824 | int status; |
| 6825 | |
| 6826 | nfs_fattr_init(&locations->fattr); |
| 6827 | locations->server = server; |
| 6828 | locations->nlocations = 0; |
| 6829 | |
| 6830 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6831 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6832 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6833 | &args.seq_args, &res.seq_res); |
| 6834 | if (status == NFS4_OK && |
| 6835 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6836 | status = -NFS4ERR_LEASE_MOVED; |
| 6837 | return status; |
| 6838 | } |
| 6839 | |
| 6840 | #endif /* CONFIG_NFS_V4_1 */ |
| 6841 | |
| 6842 | /** |
| 6843 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6844 | * @inode: inode on FSID that is migrating |
| 6845 | * @locations: result of query |
| 6846 | * @page: buffer |
| 6847 | * @cred: credential to use for this operation |
| 6848 | * |
| 6849 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6850 | * operation failed, or a negative errno if a local error occurred. |
| 6851 | * |
| 6852 | * On success, "locations" is filled in, but if the server has |
| 6853 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6854 | * asserted. |
| 6855 | * |
| 6856 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6857 | * from this client that require migration recovery. |
| 6858 | */ |
| 6859 | int nfs4_proc_get_locations(struct inode *inode, |
| 6860 | struct nfs4_fs_locations *locations, |
| 6861 | struct page *page, struct rpc_cred *cred) |
| 6862 | { |
| 6863 | struct nfs_server *server = NFS_SERVER(inode); |
| 6864 | struct nfs_client *clp = server->nfs_client; |
| 6865 | const struct nfs4_mig_recovery_ops *ops = |
| 6866 | clp->cl_mvops->mig_recovery_ops; |
| 6867 | struct nfs4_exception exception = { }; |
| 6868 | int status; |
| 6869 | |
| 6870 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6871 | (unsigned long long)server->fsid.major, |
| 6872 | (unsigned long long)server->fsid.minor, |
| 6873 | clp->cl_hostname); |
| 6874 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6875 | |
| 6876 | do { |
| 6877 | status = ops->get_locations(inode, locations, page, cred); |
| 6878 | if (status != -NFS4ERR_DELAY) |
| 6879 | break; |
| 6880 | nfs4_handle_exception(server, status, &exception); |
| 6881 | } while (exception.retry); |
| 6882 | return status; |
| 6883 | } |
| 6884 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6885 | /* |
| 6886 | * This operation also signals the server that this client is |
| 6887 | * performing "lease moved" recovery. The server can stop |
| 6888 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6889 | * is appended to this compound to identify the client ID which is |
| 6890 | * performing recovery. |
| 6891 | */ |
| 6892 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6893 | { |
| 6894 | struct nfs_server *server = NFS_SERVER(inode); |
| 6895 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6896 | struct rpc_clnt *clnt = server->client; |
| 6897 | struct nfs4_fsid_present_arg args = { |
| 6898 | .fh = NFS_FH(inode), |
| 6899 | .clientid = clp->cl_clientid, |
| 6900 | .renew = 1, /* append RENEW */ |
| 6901 | }; |
| 6902 | struct nfs4_fsid_present_res res = { |
| 6903 | .renew = 1, |
| 6904 | }; |
| 6905 | struct rpc_message msg = { |
| 6906 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6907 | .rpc_argp = &args, |
| 6908 | .rpc_resp = &res, |
| 6909 | .rpc_cred = cred, |
| 6910 | }; |
| 6911 | unsigned long now = jiffies; |
| 6912 | int status; |
| 6913 | |
| 6914 | res.fh = nfs_alloc_fhandle(); |
| 6915 | if (res.fh == NULL) |
| 6916 | return -ENOMEM; |
| 6917 | |
| 6918 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6919 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6920 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6921 | &args.seq_args, &res.seq_res); |
| 6922 | nfs_free_fhandle(res.fh); |
| 6923 | if (status) |
| 6924 | return status; |
| 6925 | |
| 6926 | do_renew_lease(clp, now); |
| 6927 | return 0; |
| 6928 | } |
| 6929 | |
| 6930 | #ifdef CONFIG_NFS_V4_1 |
| 6931 | |
| 6932 | /* |
| 6933 | * This operation also signals the server that this client is |
| 6934 | * performing "lease moved" recovery. The server can stop asserting |
| 6935 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6936 | * this operation is identified in the SEQUENCE operation in this |
| 6937 | * compound. |
| 6938 | */ |
| 6939 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6940 | { |
| 6941 | struct nfs_server *server = NFS_SERVER(inode); |
| 6942 | struct rpc_clnt *clnt = server->client; |
| 6943 | struct nfs4_fsid_present_arg args = { |
| 6944 | .fh = NFS_FH(inode), |
| 6945 | }; |
| 6946 | struct nfs4_fsid_present_res res = { |
| 6947 | }; |
| 6948 | struct rpc_message msg = { |
| 6949 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6950 | .rpc_argp = &args, |
| 6951 | .rpc_resp = &res, |
| 6952 | .rpc_cred = cred, |
| 6953 | }; |
| 6954 | int status; |
| 6955 | |
| 6956 | res.fh = nfs_alloc_fhandle(); |
| 6957 | if (res.fh == NULL) |
| 6958 | return -ENOMEM; |
| 6959 | |
| 6960 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6961 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6962 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6963 | &args.seq_args, &res.seq_res); |
| 6964 | nfs_free_fhandle(res.fh); |
| 6965 | if (status == NFS4_OK && |
| 6966 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6967 | status = -NFS4ERR_LEASE_MOVED; |
| 6968 | return status; |
| 6969 | } |
| 6970 | |
| 6971 | #endif /* CONFIG_NFS_V4_1 */ |
| 6972 | |
| 6973 | /** |
| 6974 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6975 | * @inode: inode on FSID to check |
| 6976 | * @cred: credential to use for this operation |
| 6977 | * |
| 6978 | * Server indicates whether the FSID is present, moved, or not |
| 6979 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6980 | * condition for this client ID. |
| 6981 | * |
| 6982 | * Returns NFS4_OK if the FSID is present on this server, |
| 6983 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6984 | * NFS4ERR code if some error occurred on the server, or a |
| 6985 | * negative errno if a local failure occurred. |
| 6986 | */ |
| 6987 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6988 | { |
| 6989 | struct nfs_server *server = NFS_SERVER(inode); |
| 6990 | struct nfs_client *clp = server->nfs_client; |
| 6991 | const struct nfs4_mig_recovery_ops *ops = |
| 6992 | clp->cl_mvops->mig_recovery_ops; |
| 6993 | struct nfs4_exception exception = { }; |
| 6994 | int status; |
| 6995 | |
| 6996 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6997 | (unsigned long long)server->fsid.major, |
| 6998 | (unsigned long long)server->fsid.minor, |
| 6999 | clp->cl_hostname); |
| 7000 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7001 | |
| 7002 | do { |
| 7003 | status = ops->fsid_present(inode, cred); |
| 7004 | if (status != -NFS4ERR_DELAY) |
| 7005 | break; |
| 7006 | nfs4_handle_exception(server, status, &exception); |
| 7007 | } while (exception.retry); |
| 7008 | return status; |
| 7009 | } |
| 7010 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7011 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7012 | * If 'use_integrity' is true and the state managment nfs_client |
| 7013 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7014 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7015 | * Considerations sections. Otherwise, just use the user cred with the |
| 7016 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7017 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7018 | 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] | 7019 | { |
| 7020 | int status; |
| 7021 | struct nfs4_secinfo_arg args = { |
| 7022 | .dir_fh = NFS_FH(dir), |
| 7023 | .name = name, |
| 7024 | }; |
| 7025 | struct nfs4_secinfo_res res = { |
| 7026 | .flavors = flavors, |
| 7027 | }; |
| 7028 | struct rpc_message msg = { |
| 7029 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7030 | .rpc_argp = &args, |
| 7031 | .rpc_resp = &res, |
| 7032 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7033 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7034 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7035 | |
| 7036 | if (use_integrity) { |
| 7037 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7038 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7039 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7040 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7041 | |
| 7042 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7043 | |
| 7044 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7045 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7046 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7047 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7048 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7049 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7050 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7051 | if (cred) |
| 7052 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7053 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7054 | return status; |
| 7055 | } |
| 7056 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7057 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7058 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7059 | { |
| 7060 | struct nfs4_exception exception = { }; |
| 7061 | int err; |
| 7062 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7063 | err = -NFS4ERR_WRONGSEC; |
| 7064 | |
| 7065 | /* try to use integrity protection with machine cred */ |
| 7066 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7067 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7068 | |
| 7069 | /* |
| 7070 | * if unable to use integrity protection, or SECINFO with |
| 7071 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7072 | * disallowed by spec, but exists in deployed servers) use |
| 7073 | * the current filesystem's rpc_client and the user cred. |
| 7074 | */ |
| 7075 | if (err == -NFS4ERR_WRONGSEC) |
| 7076 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7077 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7078 | trace_nfs4_secinfo(dir, name, err); |
| 7079 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7080 | &exception); |
| 7081 | } while (exception.retry); |
| 7082 | return err; |
| 7083 | } |
| 7084 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7085 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7086 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7087 | * Check the exchange flags returned by the server for invalid flags, having |
| 7088 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7089 | * DS flags set. |
| 7090 | */ |
| 7091 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7092 | { |
| 7093 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7094 | goto out_inval; |
| 7095 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7096 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7097 | goto out_inval; |
| 7098 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7099 | goto out_inval; |
| 7100 | return NFS_OK; |
| 7101 | out_inval: |
| 7102 | return -NFS4ERR_INVAL; |
| 7103 | } |
| 7104 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7105 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7106 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7107 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7108 | { |
| 7109 | if (a->server_scope_sz == b->server_scope_sz && |
| 7110 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7111 | return true; |
| 7112 | |
| 7113 | return false; |
| 7114 | } |
| 7115 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7116 | static void |
| 7117 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7118 | { |
| 7119 | } |
| 7120 | |
| 7121 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7122 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7123 | }; |
| 7124 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7125 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7126 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7127 | * |
| 7128 | * The 4.1 client currently uses the same TCP connection for the |
| 7129 | * fore and backchannel. |
| 7130 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7131 | static |
| 7132 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7133 | struct rpc_xprt *xprt, |
| 7134 | struct nfs_client *clp, |
| 7135 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7136 | { |
| 7137 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7138 | struct nfs41_bind_conn_to_session_args args = { |
| 7139 | .client = clp, |
| 7140 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7141 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7142 | struct nfs41_bind_conn_to_session_res res; |
| 7143 | struct rpc_message msg = { |
| 7144 | .rpc_proc = |
| 7145 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7146 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7147 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7148 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7149 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7150 | struct rpc_task_setup task_setup_data = { |
| 7151 | .rpc_client = clnt, |
| 7152 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7153 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7154 | .rpc_message = &msg, |
| 7155 | .flags = RPC_TASK_TIMEOUT, |
| 7156 | }; |
| 7157 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7158 | |
| 7159 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7160 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7161 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7162 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7163 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7164 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7165 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7166 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7167 | args.dir = NFS4_CDFC4_FORE; |
| 7168 | |
| 7169 | task = rpc_run_task(&task_setup_data); |
| 7170 | if (!IS_ERR(task)) { |
| 7171 | status = task->tk_status; |
| 7172 | rpc_put_task(task); |
| 7173 | } else |
| 7174 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7175 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7176 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7177 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7178 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7179 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7180 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7181 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7182 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7183 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7184 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7185 | __func__); |
| 7186 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7187 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7188 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7189 | 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] | 7190 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7191 | __func__); |
| 7192 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7193 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7194 | } |
| 7195 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7196 | out: |
| 7197 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7198 | return status; |
| 7199 | } |
| 7200 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7201 | struct rpc_bind_conn_calldata { |
| 7202 | struct nfs_client *clp; |
| 7203 | struct rpc_cred *cred; |
| 7204 | }; |
| 7205 | |
| 7206 | static int |
| 7207 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7208 | struct rpc_xprt *xprt, |
| 7209 | void *calldata) |
| 7210 | { |
| 7211 | struct rpc_bind_conn_calldata *p = calldata; |
| 7212 | |
| 7213 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7214 | } |
| 7215 | |
| 7216 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7217 | { |
| 7218 | struct rpc_bind_conn_calldata data = { |
| 7219 | .clp = clp, |
| 7220 | .cred = cred, |
| 7221 | }; |
| 7222 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7223 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7224 | } |
| 7225 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7226 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7227 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7228 | * 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] | 7229 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7230 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7231 | .how = SP4_MACH_CRED, |
| 7232 | .enforce.u.words = { |
| 7233 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7234 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7235 | 1 << (OP_CREATE_SESSION - 32) | |
| 7236 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7237 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7238 | }, |
| 7239 | .allow.u.words = { |
| 7240 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7241 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7242 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7243 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7244 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7245 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7246 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7247 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7248 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7249 | 1 << (OP_FREE_STATEID - 32) | |
| 7250 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7251 | } |
| 7252 | }; |
| 7253 | |
| 7254 | /* |
| 7255 | * Select the state protection mode for client `clp' given the server results |
| 7256 | * from exchange_id in `sp'. |
| 7257 | * |
| 7258 | * Returns 0 on success, negative errno otherwise. |
| 7259 | */ |
| 7260 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7261 | struct nfs41_state_protection *sp) |
| 7262 | { |
| 7263 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7264 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7265 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7266 | 1 << (OP_CREATE_SESSION - 32) | |
| 7267 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7268 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7269 | }; |
| 7270 | unsigned int i; |
| 7271 | |
| 7272 | if (sp->how == SP4_MACH_CRED) { |
| 7273 | /* Print state protect result */ |
| 7274 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7275 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7276 | if (test_bit(i, sp->enforce.u.longs)) |
| 7277 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7278 | if (test_bit(i, sp->allow.u.longs)) |
| 7279 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7280 | } |
| 7281 | |
| 7282 | /* make sure nothing is on enforce list that isn't supported */ |
| 7283 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7284 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7285 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7286 | return -EINVAL; |
| 7287 | } |
| 7288 | } |
| 7289 | |
| 7290 | /* |
| 7291 | * Minimal mode - state operations are allowed to use machine |
| 7292 | * credential. Note this already happens by default, so the |
| 7293 | * client doesn't have to do anything more than the negotiation. |
| 7294 | * |
| 7295 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7296 | * we're already using the machine cred for exchange_id |
| 7297 | * and will never use a different cred. |
| 7298 | */ |
| 7299 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7300 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7301 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7302 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7303 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7304 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7305 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7306 | } else { |
| 7307 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7308 | return -EINVAL; |
| 7309 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7310 | |
| 7311 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7312 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7313 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7314 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7315 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7316 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7317 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7318 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7319 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7320 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7321 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7322 | &clp->cl_sp4_flags); |
| 7323 | } |
| 7324 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7325 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7326 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7327 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7328 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7329 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7330 | |
| 7331 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7332 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7333 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7334 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7335 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7336 | |
| 7337 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7338 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7339 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7340 | } |
| 7341 | |
| 7342 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7343 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7344 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7345 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7346 | } |
| 7347 | |
| 7348 | return 0; |
| 7349 | } |
| 7350 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7351 | struct nfs41_exchange_id_data { |
| 7352 | struct nfs41_exchange_id_res res; |
| 7353 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7354 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7355 | int rpc_status; |
| 7356 | }; |
| 7357 | |
| 7358 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7359 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7360 | struct nfs41_exchange_id_data *cdata = |
| 7361 | (struct nfs41_exchange_id_data *)data; |
| 7362 | struct nfs_client *clp = cdata->args.client; |
| 7363 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7364 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7365 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7366 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7367 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7368 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7369 | |
| 7370 | if (cdata->xprt && status == 0) { |
| 7371 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7372 | cdata->xprt); |
| 7373 | goto out; |
| 7374 | } |
| 7375 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7376 | if (status == 0) |
| 7377 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7378 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7379 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7380 | clp->cl_clientid = cdata->res.clientid; |
| 7381 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7382 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7383 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7384 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7385 | &clp->cl_session->session_state); |
| 7386 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7387 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7388 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7389 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7390 | clp->cl_serverowner = cdata->res.server_owner; |
| 7391 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7392 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7393 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7394 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7395 | clp->cl_implid = cdata->res.impl_id; |
| 7396 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7397 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7398 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7399 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7400 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7401 | dprintk("%s: server_scope mismatch detected\n", |
| 7402 | __func__); |
| 7403 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7404 | kfree(clp->cl_serverscope); |
| 7405 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7406 | } |
| 7407 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7408 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7409 | clp->cl_serverscope = cdata->res.server_scope; |
| 7410 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7411 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7412 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7413 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7414 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7415 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7416 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7417 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7418 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | static void nfs4_exchange_id_release(void *data) |
| 7422 | { |
| 7423 | struct nfs41_exchange_id_data *cdata = |
| 7424 | (struct nfs41_exchange_id_data *)data; |
| 7425 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7426 | if (cdata->xprt) { |
| 7427 | xprt_put(cdata->xprt); |
| 7428 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7429 | } |
Olga Kornievskaia | b76d4fb | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7430 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7431 | kfree(cdata->res.impl_id); |
| 7432 | kfree(cdata->res.server_scope); |
| 7433 | kfree(cdata->res.server_owner); |
| 7434 | kfree(cdata); |
| 7435 | } |
| 7436 | |
| 7437 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7438 | .rpc_call_done = nfs4_exchange_id_done, |
| 7439 | .rpc_release = nfs4_exchange_id_release, |
| 7440 | }; |
| 7441 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7442 | /* |
| 7443 | * _nfs4_proc_exchange_id() |
| 7444 | * |
| 7445 | * Wrapper for EXCHANGE_ID operation. |
| 7446 | */ |
| 7447 | 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] | 7448 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7449 | { |
| 7450 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7451 | struct rpc_message msg = { |
| 7452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7453 | .rpc_cred = cred, |
| 7454 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7455 | struct rpc_task_setup task_setup_data = { |
| 7456 | .rpc_client = clp->cl_rpcclient, |
| 7457 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7458 | .rpc_message = &msg, |
| 7459 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7460 | }; |
| 7461 | struct nfs41_exchange_id_data *calldata; |
| 7462 | struct rpc_task *task; |
| 7463 | int status = -EIO; |
| 7464 | |
| 7465 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7466 | goto out; |
| 7467 | |
| 7468 | status = -ENOMEM; |
| 7469 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7470 | if (!calldata) |
| 7471 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7472 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7473 | if (!xprt) |
| 7474 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7475 | |
| 7476 | status = nfs4_init_uniform_client_string(clp); |
| 7477 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7478 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7479 | |
| 7480 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7481 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7482 | clp->cl_owner_id); |
| 7483 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7484 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7485 | GFP_NOFS); |
| 7486 | status = -ENOMEM; |
| 7487 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7488 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7489 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7490 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7491 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7492 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7493 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7494 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7495 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7496 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7497 | goto out_server_scope; |
| 7498 | |
| 7499 | switch (sp4_how) { |
| 7500 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7501 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7502 | break; |
| 7503 | |
| 7504 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7505 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7506 | break; |
| 7507 | |
| 7508 | default: |
| 7509 | /* unsupported! */ |
| 7510 | WARN_ON_ONCE(1); |
| 7511 | status = -EINVAL; |
| 7512 | goto out_impl_id; |
| 7513 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7514 | if (xprt) { |
| 7515 | calldata->xprt = xprt; |
| 7516 | task_setup_data.rpc_xprt = xprt; |
| 7517 | task_setup_data.flags = |
| 7518 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7519 | calldata->args.verifier = &clp->cl_confirm; |
| 7520 | } else { |
| 7521 | calldata->args.verifier = &verifier; |
| 7522 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7523 | calldata->args.client = clp; |
| 7524 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7525 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7526 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7527 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7528 | #else |
| 7529 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7530 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7531 | #endif |
| 7532 | msg.rpc_argp = &calldata->args; |
| 7533 | msg.rpc_resp = &calldata->res; |
| 7534 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7535 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7536 | task = rpc_run_task(&task_setup_data); |
Olga Kornievskaia | b76d4fb | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7537 | if (IS_ERR(task)) |
| 7538 | return PTR_ERR(task); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7539 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7540 | if (!xprt) { |
| 7541 | status = rpc_wait_for_completion_task(task); |
| 7542 | if (!status) |
| 7543 | status = calldata->rpc_status; |
| 7544 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7545 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7546 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7547 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7548 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7549 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7550 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7551 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7552 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7553 | clp->cl_implid->date.seconds, |
| 7554 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7555 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7556 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7557 | |
| 7558 | out_impl_id: |
| 7559 | kfree(calldata->res.impl_id); |
| 7560 | out_server_scope: |
| 7561 | kfree(calldata->res.server_scope); |
| 7562 | out_server_owner: |
| 7563 | kfree(calldata->res.server_owner); |
| 7564 | out_calldata: |
| 7565 | kfree(calldata); |
Olga Kornievskaia | b76d4fb | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7566 | nfs_put_client(clp); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7567 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7568 | } |
| 7569 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7570 | /* |
| 7571 | * nfs4_proc_exchange_id() |
| 7572 | * |
| 7573 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7574 | * |
| 7575 | * Since the clientid has expired, all compounds using sessions |
| 7576 | * associated with the stale clientid will be returning |
| 7577 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7578 | * be in some phase of session reset. |
| 7579 | * |
| 7580 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7581 | */ |
| 7582 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7583 | { |
| 7584 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7585 | int status; |
| 7586 | |
| 7587 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7588 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7589 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7590 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7591 | if (!status) |
| 7592 | return 0; |
| 7593 | } |
| 7594 | |
| 7595 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7596 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7597 | } |
| 7598 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7599 | /** |
| 7600 | * nfs4_test_session_trunk |
| 7601 | * |
| 7602 | * This is an add_xprt_test() test function called from |
| 7603 | * rpc_clnt_setup_test_and_add_xprt. |
| 7604 | * |
| 7605 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7606 | * and is dereferrenced in nfs4_exchange_id_release |
| 7607 | * |
| 7608 | * Upon success, add the new transport to the rpc_clnt |
| 7609 | * |
| 7610 | * @clnt: struct rpc_clnt to get new transport |
| 7611 | * @xprt: the rpc_xprt to test |
| 7612 | * @data: call data for _nfs4_proc_exchange_id. |
| 7613 | */ |
| 7614 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7615 | void *data) |
| 7616 | { |
| 7617 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7618 | u32 sp4_how; |
| 7619 | |
| 7620 | dprintk("--> %s try %s\n", __func__, |
| 7621 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7622 | |
| 7623 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7624 | |
| 7625 | /* Test connection for session trunking. Async exchange_id call */ |
| 7626 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7627 | } |
| 7628 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7629 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7630 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7631 | struct rpc_cred *cred) |
| 7632 | { |
| 7633 | struct rpc_message msg = { |
| 7634 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7635 | .rpc_argp = clp, |
| 7636 | .rpc_cred = cred, |
| 7637 | }; |
| 7638 | int status; |
| 7639 | |
| 7640 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7641 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7642 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7643 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7644 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7645 | return status; |
| 7646 | } |
| 7647 | |
| 7648 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7649 | struct rpc_cred *cred) |
| 7650 | { |
| 7651 | unsigned int loop; |
| 7652 | int ret; |
| 7653 | |
| 7654 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7655 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7656 | switch (ret) { |
| 7657 | case -NFS4ERR_DELAY: |
| 7658 | case -NFS4ERR_CLIENTID_BUSY: |
| 7659 | ssleep(1); |
| 7660 | break; |
| 7661 | default: |
| 7662 | return ret; |
| 7663 | } |
| 7664 | } |
| 7665 | return 0; |
| 7666 | } |
| 7667 | |
| 7668 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7669 | { |
| 7670 | struct rpc_cred *cred; |
| 7671 | int ret = 0; |
| 7672 | |
| 7673 | if (clp->cl_mvops->minor_version < 1) |
| 7674 | goto out; |
| 7675 | if (clp->cl_exchange_flags == 0) |
| 7676 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7677 | if (clp->cl_preserve_clid) |
| 7678 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7679 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7680 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7681 | if (cred) |
| 7682 | put_rpccred(cred); |
| 7683 | switch (ret) { |
| 7684 | case 0: |
| 7685 | case -NFS4ERR_STALE_CLIENTID: |
| 7686 | clp->cl_exchange_flags = 0; |
| 7687 | } |
| 7688 | out: |
| 7689 | return ret; |
| 7690 | } |
| 7691 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7692 | struct nfs4_get_lease_time_data { |
| 7693 | struct nfs4_get_lease_time_args *args; |
| 7694 | struct nfs4_get_lease_time_res *res; |
| 7695 | struct nfs_client *clp; |
| 7696 | }; |
| 7697 | |
| 7698 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7699 | void *calldata) |
| 7700 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7701 | struct nfs4_get_lease_time_data *data = |
| 7702 | (struct nfs4_get_lease_time_data *)calldata; |
| 7703 | |
| 7704 | dprintk("--> %s\n", __func__); |
| 7705 | /* just setup sequence, do not trigger session recovery |
| 7706 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7707 | nfs41_setup_sequence(data->clp->cl_session, |
| 7708 | &data->args->la_seq_args, |
| 7709 | &data->res->lr_seq_res, |
| 7710 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7711 | dprintk("<-- %s\n", __func__); |
| 7712 | } |
| 7713 | |
| 7714 | /* |
| 7715 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7716 | * from sequence operation or clientid errors. |
| 7717 | */ |
| 7718 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7719 | { |
| 7720 | struct nfs4_get_lease_time_data *data = |
| 7721 | (struct nfs4_get_lease_time_data *)calldata; |
| 7722 | |
| 7723 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7724 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7725 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7726 | switch (task->tk_status) { |
| 7727 | case -NFS4ERR_DELAY: |
| 7728 | case -NFS4ERR_GRACE: |
| 7729 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7730 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7731 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7732 | /* fall through */ |
| 7733 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7734 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7735 | return; |
| 7736 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7737 | dprintk("<-- %s\n", __func__); |
| 7738 | } |
| 7739 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7740 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7741 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7742 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7743 | }; |
| 7744 | |
| 7745 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7746 | { |
| 7747 | struct rpc_task *task; |
| 7748 | struct nfs4_get_lease_time_args args; |
| 7749 | struct nfs4_get_lease_time_res res = { |
| 7750 | .lr_fsinfo = fsinfo, |
| 7751 | }; |
| 7752 | struct nfs4_get_lease_time_data data = { |
| 7753 | .args = &args, |
| 7754 | .res = &res, |
| 7755 | .clp = clp, |
| 7756 | }; |
| 7757 | struct rpc_message msg = { |
| 7758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7759 | .rpc_argp = &args, |
| 7760 | .rpc_resp = &res, |
| 7761 | }; |
| 7762 | struct rpc_task_setup task_setup = { |
| 7763 | .rpc_client = clp->cl_rpcclient, |
| 7764 | .rpc_message = &msg, |
| 7765 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7766 | .callback_data = &data, |
| 7767 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7768 | }; |
| 7769 | int status; |
| 7770 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7771 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7772 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7773 | dprintk("--> %s\n", __func__); |
| 7774 | task = rpc_run_task(&task_setup); |
| 7775 | |
| 7776 | if (IS_ERR(task)) |
| 7777 | status = PTR_ERR(task); |
| 7778 | else { |
| 7779 | status = task->tk_status; |
| 7780 | rpc_put_task(task); |
| 7781 | } |
| 7782 | dprintk("<-- %s return %d\n", __func__, status); |
| 7783 | |
| 7784 | return status; |
| 7785 | } |
| 7786 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7787 | /* |
| 7788 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7789 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7790 | * use them. |
| 7791 | * |
| 7792 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7793 | * always set csa_cachethis to FALSE because the current implementation |
| 7794 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7795 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7796 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7797 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7798 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7799 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7800 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7801 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7802 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7803 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7804 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7805 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7806 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7807 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7808 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7809 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7810 | |
| 7811 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7812 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7813 | __func__, |
| 7814 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7815 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7816 | |
| 7817 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7818 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7819 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7820 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7821 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7822 | 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] | 7823 | |
| 7824 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7825 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7826 | __func__, |
| 7827 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7828 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7829 | args->bc_attrs.max_reqs); |
| 7830 | } |
| 7831 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7832 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7833 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7834 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7835 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7836 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7837 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7838 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7839 | return -EINVAL; |
| 7840 | /* |
| 7841 | * Our requested max_ops is the minimum we need; we're not |
| 7842 | * prepared to break up compounds into smaller pieces than that. |
| 7843 | * So, no point even trying to continue if the server won't |
| 7844 | * cooperate: |
| 7845 | */ |
| 7846 | if (rcvd->max_ops < sent->max_ops) |
| 7847 | return -EINVAL; |
| 7848 | if (rcvd->max_reqs == 0) |
| 7849 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7850 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7851 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7852 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7853 | } |
| 7854 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7855 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7856 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7857 | { |
| 7858 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7859 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7860 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7861 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7862 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7863 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7864 | return -EINVAL; |
| 7865 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7866 | return -EINVAL; |
| 7867 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7868 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7869 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7870 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7871 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7872 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7873 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7874 | return 0; |
| 7875 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7876 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7877 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7878 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7879 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7880 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7881 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7882 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7883 | if (ret) |
| 7884 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7885 | return nfs4_verify_back_channel_attrs(args, res); |
| 7886 | } |
| 7887 | |
| 7888 | static void nfs4_update_session(struct nfs4_session *session, |
| 7889 | struct nfs41_create_session_res *res) |
| 7890 | { |
| 7891 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7892 | /* Mark client id and session as being confirmed */ |
| 7893 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7894 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7895 | session->flags = res->flags; |
| 7896 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7897 | if (res->flags & SESSION4_BACK_CHAN) |
| 7898 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7899 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7900 | } |
| 7901 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7902 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7903 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7904 | { |
| 7905 | struct nfs4_session *session = clp->cl_session; |
| 7906 | struct nfs41_create_session_args args = { |
| 7907 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7908 | .clientid = clp->cl_clientid, |
| 7909 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7910 | .cb_program = NFS4_CALLBACK, |
| 7911 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7912 | struct nfs41_create_session_res res; |
| 7913 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7914 | struct rpc_message msg = { |
| 7915 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7916 | .rpc_argp = &args, |
| 7917 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7918 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7919 | }; |
| 7920 | int status; |
| 7921 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7922 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7923 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7924 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7925 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7926 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7927 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7928 | switch (status) { |
| 7929 | case -NFS4ERR_STALE_CLIENTID: |
| 7930 | case -NFS4ERR_DELAY: |
| 7931 | case -ETIMEDOUT: |
| 7932 | case -EACCES: |
| 7933 | case -EAGAIN: |
| 7934 | goto out; |
| 7935 | }; |
| 7936 | |
| 7937 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7938 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7939 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7940 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7941 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7942 | if (status) |
| 7943 | goto out; |
| 7944 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7945 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7946 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7947 | return status; |
| 7948 | } |
| 7949 | |
| 7950 | /* |
| 7951 | * Issues a CREATE_SESSION operation to the server. |
| 7952 | * It is the responsibility of the caller to verify the session is |
| 7953 | * expired before calling this routine. |
| 7954 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7955 | 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] | 7956 | { |
| 7957 | int status; |
| 7958 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7959 | struct nfs4_session *session = clp->cl_session; |
| 7960 | |
| 7961 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7962 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7963 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7964 | if (status) |
| 7965 | goto out; |
| 7966 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7967 | /* Init or reset the session slot tables */ |
| 7968 | status = nfs4_setup_session_slot_tables(session); |
| 7969 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7970 | if (status) |
| 7971 | goto out; |
| 7972 | |
| 7973 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7974 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7975 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7976 | out: |
| 7977 | dprintk("<-- %s\n", __func__); |
| 7978 | return status; |
| 7979 | } |
| 7980 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7981 | /* |
| 7982 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7983 | * The caller must serialize access to this routine. |
| 7984 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7985 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7986 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7987 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7988 | struct rpc_message msg = { |
| 7989 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7990 | .rpc_argp = session, |
| 7991 | .rpc_cred = cred, |
| 7992 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7993 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7994 | |
| 7995 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7996 | |
| 7997 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7998 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7999 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8000 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8001 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8002 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8003 | |
| 8004 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8005 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8006 | "Session has been destroyed regardless...\n", status); |
| 8007 | |
| 8008 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8009 | return status; |
| 8010 | } |
| 8011 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8012 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8013 | * Renew the cl_session lease. |
| 8014 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8015 | struct nfs4_sequence_data { |
| 8016 | struct nfs_client *clp; |
| 8017 | struct nfs4_sequence_args args; |
| 8018 | struct nfs4_sequence_res res; |
| 8019 | }; |
| 8020 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8021 | static void nfs41_sequence_release(void *data) |
| 8022 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8023 | struct nfs4_sequence_data *calldata = data; |
| 8024 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8025 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8026 | if (atomic_read(&clp->cl_count) > 1) |
| 8027 | nfs4_schedule_state_renewal(clp); |
| 8028 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8029 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8030 | } |
| 8031 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8032 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8033 | { |
| 8034 | switch(task->tk_status) { |
| 8035 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8036 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8037 | return -EAGAIN; |
| 8038 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8039 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8040 | } |
| 8041 | return 0; |
| 8042 | } |
| 8043 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8044 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8045 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8046 | struct nfs4_sequence_data *calldata = data; |
| 8047 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8048 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8049 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8050 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8051 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8052 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8053 | if (task->tk_status < 0) { |
| 8054 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8055 | if (atomic_read(&clp->cl_count) == 1) |
| 8056 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8057 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8058 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8059 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8060 | return; |
| 8061 | } |
| 8062 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8063 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8064 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8065 | dprintk("<-- %s\n", __func__); |
| 8066 | } |
| 8067 | |
| 8068 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8069 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8070 | struct nfs4_sequence_data *calldata = data; |
| 8071 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8072 | struct nfs4_sequence_args *args; |
| 8073 | struct nfs4_sequence_res *res; |
| 8074 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8075 | args = task->tk_msg.rpc_argp; |
| 8076 | res = task->tk_msg.rpc_resp; |
| 8077 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8078 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8079 | } |
| 8080 | |
| 8081 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8082 | .rpc_call_done = nfs41_sequence_call_done, |
| 8083 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8084 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8085 | }; |
| 8086 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8087 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8088 | struct rpc_cred *cred, |
| 8089 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8090 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8091 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8092 | struct rpc_message msg = { |
| 8093 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8094 | .rpc_cred = cred, |
| 8095 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8096 | struct rpc_task_setup task_setup_data = { |
| 8097 | .rpc_client = clp->cl_rpcclient, |
| 8098 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8099 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8100 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8101 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8102 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8103 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8104 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8105 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8106 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8107 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8108 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8109 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8110 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8111 | if (is_privileged) |
| 8112 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8113 | msg.rpc_argp = &calldata->args; |
| 8114 | msg.rpc_resp = &calldata->res; |
| 8115 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8116 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8117 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8118 | return rpc_run_task(&task_setup_data); |
| 8119 | } |
| 8120 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8121 | 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] | 8122 | { |
| 8123 | struct rpc_task *task; |
| 8124 | int ret = 0; |
| 8125 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8126 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8127 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8128 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8129 | if (IS_ERR(task)) |
| 8130 | ret = PTR_ERR(task); |
| 8131 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8132 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8133 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8134 | return ret; |
| 8135 | } |
| 8136 | |
| 8137 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8138 | { |
| 8139 | struct rpc_task *task; |
| 8140 | int ret; |
| 8141 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8142 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8143 | if (IS_ERR(task)) { |
| 8144 | ret = PTR_ERR(task); |
| 8145 | goto out; |
| 8146 | } |
| 8147 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8148 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8149 | ret = task->tk_status; |
| 8150 | rpc_put_task(task); |
| 8151 | out: |
| 8152 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8153 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8154 | } |
| 8155 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8156 | struct nfs4_reclaim_complete_data { |
| 8157 | struct nfs_client *clp; |
| 8158 | struct nfs41_reclaim_complete_args arg; |
| 8159 | struct nfs41_reclaim_complete_res res; |
| 8160 | }; |
| 8161 | |
| 8162 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8163 | { |
| 8164 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8165 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8166 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8167 | &calldata->arg.seq_args, |
| 8168 | &calldata->res.seq_res, |
| 8169 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8170 | } |
| 8171 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8172 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8173 | { |
| 8174 | switch(task->tk_status) { |
| 8175 | case 0: |
| 8176 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8177 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8178 | break; |
| 8179 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8180 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8181 | /* fall through */ |
| 8182 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8183 | return -EAGAIN; |
| 8184 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8185 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8186 | } |
| 8187 | return 0; |
| 8188 | } |
| 8189 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8190 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8191 | { |
| 8192 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8193 | struct nfs_client *clp = calldata->clp; |
| 8194 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8195 | |
| 8196 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8197 | if (!nfs41_sequence_done(task, res)) |
| 8198 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8199 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8200 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8201 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8202 | rpc_restart_call_prepare(task); |
| 8203 | return; |
| 8204 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8205 | dprintk("<-- %s\n", __func__); |
| 8206 | } |
| 8207 | |
| 8208 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8209 | { |
| 8210 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8211 | |
| 8212 | kfree(calldata); |
| 8213 | } |
| 8214 | |
| 8215 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8216 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8217 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8218 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8219 | }; |
| 8220 | |
| 8221 | /* |
| 8222 | * Issue a global reclaim complete. |
| 8223 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8224 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8225 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8226 | { |
| 8227 | struct nfs4_reclaim_complete_data *calldata; |
| 8228 | struct rpc_task *task; |
| 8229 | struct rpc_message msg = { |
| 8230 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8231 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8232 | }; |
| 8233 | struct rpc_task_setup task_setup_data = { |
| 8234 | .rpc_client = clp->cl_rpcclient, |
| 8235 | .rpc_message = &msg, |
| 8236 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8237 | .flags = RPC_TASK_ASYNC, |
| 8238 | }; |
| 8239 | int status = -ENOMEM; |
| 8240 | |
| 8241 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8242 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8243 | if (calldata == NULL) |
| 8244 | goto out; |
| 8245 | calldata->clp = clp; |
| 8246 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8247 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8248 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8249 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8250 | msg.rpc_argp = &calldata->arg; |
| 8251 | msg.rpc_resp = &calldata->res; |
| 8252 | task_setup_data.callback_data = calldata; |
| 8253 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8254 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8255 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8256 | goto out; |
| 8257 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8258 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8259 | if (status == 0) |
| 8260 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8261 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8262 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8263 | out: |
| 8264 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8265 | return status; |
| 8266 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8267 | |
| 8268 | static void |
| 8269 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8270 | { |
| 8271 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8272 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8273 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8274 | |
| 8275 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8276 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8277 | &lgp->res.seq_res, task); |
| 8278 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8282 | { |
| 8283 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8284 | |
| 8285 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8286 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8287 | dprintk("<-- %s\n", __func__); |
| 8288 | } |
| 8289 | |
| 8290 | static int |
| 8291 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8292 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8293 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8294 | struct inode *inode = lgp->args.inode; |
| 8295 | struct nfs_server *server = NFS_SERVER(inode); |
| 8296 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8297 | int nfs4err = task->tk_status; |
| 8298 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8299 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8300 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8301 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8302 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8303 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8304 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8305 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8306 | |
| 8307 | /* |
| 8308 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8309 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8310 | * retry go inband. |
| 8311 | */ |
| 8312 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8313 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8314 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8315 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8316 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8317 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8318 | */ |
| 8319 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8320 | status = -EOVERFLOW; |
| 8321 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8322 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8323 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8324 | * (or clients) writing to the same RAID stripe except when |
| 8325 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8326 | * |
| 8327 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8328 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8329 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8330 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8331 | if (lgp->args.minlength == 0) { |
| 8332 | status = -EOVERFLOW; |
| 8333 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8334 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8335 | status = -EBUSY; |
| 8336 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8337 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8338 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8339 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8340 | case -NFS4ERR_DELEG_REVOKED: |
| 8341 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8342 | case -NFS4ERR_EXPIRED: |
| 8343 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8344 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8345 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8346 | lo = NFS_I(inode)->layout; |
| 8347 | /* If the open stateid was bad, then recover it. */ |
| 8348 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8349 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8350 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8351 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8352 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8353 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8354 | break; |
| 8355 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8356 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8357 | /* |
| 8358 | * Mark the bad layout state as invalid, then retry |
| 8359 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8360 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8361 | spin_unlock(&inode->i_lock); |
| 8362 | pnfs_free_lseg_list(&head); |
| 8363 | status = -EAGAIN; |
| 8364 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8365 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8366 | |
Trond Myklebust | 0a70235 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8367 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8368 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8369 | if (!status) { |
| 8370 | if (exception->retry) |
| 8371 | status = -EAGAIN; |
| 8372 | else |
| 8373 | status = err; |
| 8374 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8375 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8376 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8377 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8378 | } |
| 8379 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8380 | static size_t max_response_pages(struct nfs_server *server) |
| 8381 | { |
| 8382 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8383 | return nfs_page_array_len(0, max_resp_sz); |
| 8384 | } |
| 8385 | |
| 8386 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8387 | { |
| 8388 | int i; |
| 8389 | |
| 8390 | if (!pages) |
| 8391 | return; |
| 8392 | |
| 8393 | for (i = 0; i < size; i++) { |
| 8394 | if (!pages[i]) |
| 8395 | break; |
| 8396 | __free_page(pages[i]); |
| 8397 | } |
| 8398 | kfree(pages); |
| 8399 | } |
| 8400 | |
| 8401 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8402 | { |
| 8403 | struct page **pages; |
| 8404 | int i; |
| 8405 | |
| 8406 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8407 | if (!pages) { |
| 8408 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8409 | return NULL; |
| 8410 | } |
| 8411 | |
| 8412 | for (i = 0; i < size; i++) { |
| 8413 | pages[i] = alloc_page(gfp_flags); |
| 8414 | if (!pages[i]) { |
| 8415 | dprintk("%s: failed to allocate page\n", __func__); |
| 8416 | nfs4_free_pages(pages, size); |
| 8417 | return NULL; |
| 8418 | } |
| 8419 | } |
| 8420 | |
| 8421 | return pages; |
| 8422 | } |
| 8423 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8424 | static void nfs4_layoutget_release(void *calldata) |
| 8425 | { |
| 8426 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8427 | struct inode *inode = lgp->args.inode; |
| 8428 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8429 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8430 | |
| 8431 | dprintk("--> %s\n", __func__); |
Trond Myklebust | cb2c6fd | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8432 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8433 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8434 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8435 | put_nfs_open_context(lgp->args.ctx); |
| 8436 | kfree(calldata); |
| 8437 | dprintk("<-- %s\n", __func__); |
| 8438 | } |
| 8439 | |
| 8440 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8441 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8442 | .rpc_call_done = nfs4_layoutget_done, |
| 8443 | .rpc_release = nfs4_layoutget_release, |
| 8444 | }; |
| 8445 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8446 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8447 | 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] | 8448 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8449 | struct inode *inode = lgp->args.inode; |
| 8450 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8451 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8452 | struct rpc_task *task; |
| 8453 | struct rpc_message msg = { |
| 8454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8455 | .rpc_argp = &lgp->args, |
| 8456 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8457 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8458 | }; |
| 8459 | struct rpc_task_setup task_setup_data = { |
| 8460 | .rpc_client = server->client, |
| 8461 | .rpc_message = &msg, |
| 8462 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8463 | .callback_data = lgp, |
| 8464 | .flags = RPC_TASK_ASYNC, |
| 8465 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8466 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8467 | struct nfs4_exception exception = { |
| 8468 | .inode = inode, |
| 8469 | .timeout = *timeout, |
| 8470 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8471 | int status = 0; |
| 8472 | |
| 8473 | dprintk("--> %s\n", __func__); |
| 8474 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8475 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8476 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8477 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8478 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8479 | if (!lgp->args.layout.pages) { |
| 8480 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8481 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8482 | } |
| 8483 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8484 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8485 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8486 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8487 | 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] | 8488 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8489 | task = rpc_run_task(&task_setup_data); |
| 8490 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8491 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8492 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8493 | if (status == 0) { |
| 8494 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8495 | *timeout = exception.timeout; |
| 8496 | } |
| 8497 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8498 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8499 | &lgp->args.range, |
| 8500 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8501 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8502 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8503 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8504 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8505 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8506 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8507 | rpc_put_task(task); |
| 8508 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8509 | if (status) |
| 8510 | return ERR_PTR(status); |
| 8511 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8512 | } |
| 8513 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8514 | static void |
| 8515 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8516 | { |
| 8517 | struct nfs4_layoutreturn *lrp = calldata; |
| 8518 | |
| 8519 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8520 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8521 | &lrp->args.seq_args, |
| 8522 | &lrp->res.seq_res, |
| 8523 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8524 | } |
| 8525 | |
| 8526 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8527 | { |
| 8528 | struct nfs4_layoutreturn *lrp = calldata; |
| 8529 | struct nfs_server *server; |
| 8530 | |
| 8531 | dprintk("--> %s\n", __func__); |
| 8532 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8533 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8534 | return; |
| 8535 | |
| 8536 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8537 | switch (task->tk_status) { |
| 8538 | default: |
| 8539 | task->tk_status = 0; |
| 8540 | case 0: |
| 8541 | break; |
| 8542 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8543 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8544 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8545 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8546 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8547 | return; |
| 8548 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8549 | dprintk("<-- %s\n", __func__); |
| 8550 | } |
| 8551 | |
| 8552 | static void nfs4_layoutreturn_release(void *calldata) |
| 8553 | { |
| 8554 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8555 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8556 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8557 | |
| 8558 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8559 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8560 | if (lrp->res.lrs_present) { |
| 8561 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8562 | &lrp->args.range, |
| 8563 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8564 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8565 | } else |
| 8566 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8567 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8568 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8569 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8570 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8571 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8572 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8573 | kfree(calldata); |
| 8574 | dprintk("<-- %s\n", __func__); |
| 8575 | } |
| 8576 | |
| 8577 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8578 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8579 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8580 | .rpc_release = nfs4_layoutreturn_release, |
| 8581 | }; |
| 8582 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8583 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8584 | { |
| 8585 | struct rpc_task *task; |
| 8586 | struct rpc_message msg = { |
| 8587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8588 | .rpc_argp = &lrp->args, |
| 8589 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8590 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8591 | }; |
| 8592 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8593 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8594 | .rpc_message = &msg, |
| 8595 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8596 | .callback_data = lrp, |
| 8597 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8598 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8599 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8600 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8601 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8602 | &task_setup_data.rpc_client, &msg); |
| 8603 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8604 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8605 | if (!sync) { |
| 8606 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8607 | if (!lrp->inode) { |
| 8608 | nfs4_layoutreturn_release(lrp); |
| 8609 | return -EAGAIN; |
| 8610 | } |
| 8611 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8612 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8613 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8614 | task = rpc_run_task(&task_setup_data); |
| 8615 | if (IS_ERR(task)) |
| 8616 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8617 | if (sync) |
| 8618 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8619 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8620 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8621 | rpc_put_task(task); |
| 8622 | return status; |
| 8623 | } |
| 8624 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8625 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8626 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8627 | struct pnfs_device *pdev, |
| 8628 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8629 | { |
| 8630 | struct nfs4_getdeviceinfo_args args = { |
| 8631 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8632 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8633 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8634 | }; |
| 8635 | struct nfs4_getdeviceinfo_res res = { |
| 8636 | .pdev = pdev, |
| 8637 | }; |
| 8638 | struct rpc_message msg = { |
| 8639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8640 | .rpc_argp = &args, |
| 8641 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8642 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8643 | }; |
| 8644 | int status; |
| 8645 | |
| 8646 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8647 | 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] | 8648 | if (res.notification & ~args.notify_types) |
| 8649 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8650 | if (res.notification != args.notify_types) |
| 8651 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8652 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8653 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8654 | |
| 8655 | return status; |
| 8656 | } |
| 8657 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8658 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8659 | struct pnfs_device *pdev, |
| 8660 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8661 | { |
| 8662 | struct nfs4_exception exception = { }; |
| 8663 | int err; |
| 8664 | |
| 8665 | do { |
| 8666 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8667 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8668 | &exception); |
| 8669 | } while (exception.retry); |
| 8670 | return err; |
| 8671 | } |
| 8672 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8673 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8674 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8675 | { |
| 8676 | struct nfs4_layoutcommit_data *data = calldata; |
| 8677 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8678 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8679 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8680 | nfs41_setup_sequence(session, |
| 8681 | &data->args.seq_args, |
| 8682 | &data->res.seq_res, |
| 8683 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8684 | } |
| 8685 | |
| 8686 | static void |
| 8687 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8688 | { |
| 8689 | struct nfs4_layoutcommit_data *data = calldata; |
| 8690 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8691 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8692 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8693 | return; |
| 8694 | |
| 8695 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8696 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8697 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8698 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8699 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8700 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8701 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8702 | break; |
| 8703 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8704 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8705 | rpc_restart_call_prepare(task); |
| 8706 | return; |
| 8707 | } |
| 8708 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8709 | } |
| 8710 | |
| 8711 | static void nfs4_layoutcommit_release(void *calldata) |
| 8712 | { |
| 8713 | struct nfs4_layoutcommit_data *data = calldata; |
| 8714 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8715 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8716 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8717 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8718 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8719 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8720 | kfree(data); |
| 8721 | } |
| 8722 | |
| 8723 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8724 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8725 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8726 | .rpc_release = nfs4_layoutcommit_release, |
| 8727 | }; |
| 8728 | |
| 8729 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8730 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8731 | { |
| 8732 | struct rpc_message msg = { |
| 8733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8734 | .rpc_argp = &data->args, |
| 8735 | .rpc_resp = &data->res, |
| 8736 | .rpc_cred = data->cred, |
| 8737 | }; |
| 8738 | struct rpc_task_setup task_setup_data = { |
| 8739 | .task = &data->task, |
| 8740 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8741 | .rpc_message = &msg, |
| 8742 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8743 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8744 | }; |
| 8745 | struct rpc_task *task; |
| 8746 | int status = 0; |
| 8747 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8748 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8749 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8750 | data->args.lastbytewritten, |
| 8751 | data->args.inode->i_ino); |
| 8752 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8753 | if (!sync) { |
| 8754 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8755 | if (data->inode == NULL) { |
| 8756 | nfs4_layoutcommit_release(data); |
| 8757 | return -EAGAIN; |
| 8758 | } |
| 8759 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8760 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8761 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8762 | task = rpc_run_task(&task_setup_data); |
| 8763 | if (IS_ERR(task)) |
| 8764 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8765 | if (sync) |
| 8766 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8767 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8768 | dprintk("%s: status %d\n", __func__, status); |
| 8769 | rpc_put_task(task); |
| 8770 | return status; |
| 8771 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8772 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8773 | /** |
| 8774 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8775 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8776 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8777 | static int |
| 8778 | _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] | 8779 | struct nfs_fsinfo *info, |
| 8780 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8781 | { |
| 8782 | struct nfs41_secinfo_no_name_args args = { |
| 8783 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8784 | }; |
| 8785 | struct nfs4_secinfo_res res = { |
| 8786 | .flavors = flavors, |
| 8787 | }; |
| 8788 | struct rpc_message msg = { |
| 8789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8790 | .rpc_argp = &args, |
| 8791 | .rpc_resp = &res, |
| 8792 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8793 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8794 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8795 | int status; |
| 8796 | |
| 8797 | if (use_integrity) { |
| 8798 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8799 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8800 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | dprintk("--> %s\n", __func__); |
| 8804 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8805 | &res.seq_res, 0); |
| 8806 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8807 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8808 | if (cred) |
| 8809 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8810 | |
| 8811 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8812 | } |
| 8813 | |
| 8814 | static int |
| 8815 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8816 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8817 | { |
| 8818 | struct nfs4_exception exception = { }; |
| 8819 | int err; |
| 8820 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8821 | /* first try using integrity protection */ |
| 8822 | err = -NFS4ERR_WRONGSEC; |
| 8823 | |
| 8824 | /* try to use integrity protection with machine cred */ |
| 8825 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8826 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8827 | flavors, true); |
| 8828 | |
| 8829 | /* |
| 8830 | * if unable to use integrity protection, or SECINFO with |
| 8831 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8832 | * disallowed by spec, but exists in deployed servers) use |
| 8833 | * the current filesystem's rpc_client and the user cred. |
| 8834 | */ |
| 8835 | if (err == -NFS4ERR_WRONGSEC) |
| 8836 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8837 | flavors, false); |
| 8838 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8839 | switch (err) { |
| 8840 | case 0: |
| 8841 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8842 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8843 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8844 | default: |
| 8845 | err = nfs4_handle_exception(server, err, &exception); |
| 8846 | } |
| 8847 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8848 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8849 | return err; |
| 8850 | } |
| 8851 | |
| 8852 | static int |
| 8853 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8854 | struct nfs_fsinfo *info) |
| 8855 | { |
| 8856 | int err; |
| 8857 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8858 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8859 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8860 | struct nfs4_secinfo4 *secinfo; |
| 8861 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8862 | |
| 8863 | page = alloc_page(GFP_KERNEL); |
| 8864 | if (!page) { |
| 8865 | err = -ENOMEM; |
| 8866 | goto out; |
| 8867 | } |
| 8868 | |
| 8869 | flavors = page_address(page); |
| 8870 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8871 | |
| 8872 | /* |
| 8873 | * Fall back on "guess and check" method if |
| 8874 | * the server doesn't support SECINFO_NO_NAME |
| 8875 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8876 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8877 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8878 | goto out_freepage; |
| 8879 | } |
| 8880 | if (err) |
| 8881 | goto out_freepage; |
| 8882 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8883 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8884 | secinfo = &flavors->flavors[i]; |
| 8885 | |
| 8886 | switch (secinfo->flavor) { |
| 8887 | case RPC_AUTH_NULL: |
| 8888 | case RPC_AUTH_UNIX: |
| 8889 | case RPC_AUTH_GSS: |
| 8890 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8891 | &secinfo->flavor_info); |
| 8892 | break; |
| 8893 | default: |
| 8894 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8895 | break; |
| 8896 | } |
| 8897 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8898 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8899 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8900 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8901 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8902 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8903 | info, flavor); |
| 8904 | if (!err) |
| 8905 | break; |
| 8906 | } |
| 8907 | } |
| 8908 | |
| 8909 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8910 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8911 | |
| 8912 | out_freepage: |
| 8913 | put_page(page); |
| 8914 | if (err == -EACCES) |
| 8915 | return -EPERM; |
| 8916 | out: |
| 8917 | return err; |
| 8918 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8919 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8920 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8921 | nfs4_stateid *stateid, |
| 8922 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8923 | { |
| 8924 | int status; |
| 8925 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8926 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8927 | }; |
| 8928 | struct nfs41_test_stateid_res res; |
| 8929 | struct rpc_message msg = { |
| 8930 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8931 | .rpc_argp = &args, |
| 8932 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8933 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8934 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8935 | struct rpc_clnt *rpc_client = server->client; |
| 8936 | |
| 8937 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8938 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8939 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8940 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8941 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8942 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8943 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8944 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8945 | if (status != NFS_OK) { |
| 8946 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8947 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8948 | } |
| 8949 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8950 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8951 | } |
| 8952 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8953 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8954 | int err, struct nfs4_exception *exception) |
| 8955 | { |
| 8956 | exception->retry = 0; |
| 8957 | switch(err) { |
| 8958 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8959 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8960 | nfs4_handle_exception(server, err, exception); |
| 8961 | break; |
| 8962 | case -NFS4ERR_BADSESSION: |
| 8963 | case -NFS4ERR_BADSLOT: |
| 8964 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8965 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8966 | case -NFS4ERR_DEADSESSION: |
| 8967 | nfs4_do_handle_exception(server, err, exception); |
| 8968 | } |
| 8969 | } |
| 8970 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8971 | /** |
| 8972 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8973 | * |
| 8974 | * @server: server / transport on which to perform the operation |
| 8975 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8976 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8977 | * |
| 8978 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8979 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8980 | * failed or the state ID is not currently valid. |
| 8981 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8982 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8983 | nfs4_stateid *stateid, |
| 8984 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8985 | { |
| 8986 | struct nfs4_exception exception = { }; |
| 8987 | int err; |
| 8988 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8989 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8990 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8991 | } while (exception.retry); |
| 8992 | return err; |
| 8993 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8994 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8995 | struct nfs_free_stateid_data { |
| 8996 | struct nfs_server *server; |
| 8997 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8998 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8999 | }; |
| 9000 | |
| 9001 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9002 | { |
| 9003 | struct nfs_free_stateid_data *data = calldata; |
| 9004 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 9005 | &data->args.seq_args, |
| 9006 | &data->res.seq_res, |
| 9007 | task); |
| 9008 | } |
| 9009 | |
| 9010 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9011 | { |
| 9012 | struct nfs_free_stateid_data *data = calldata; |
| 9013 | |
| 9014 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9015 | |
| 9016 | switch (task->tk_status) { |
| 9017 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9018 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9019 | rpc_restart_call_prepare(task); |
| 9020 | } |
| 9021 | } |
| 9022 | |
| 9023 | static void nfs41_free_stateid_release(void *calldata) |
| 9024 | { |
| 9025 | kfree(calldata); |
| 9026 | } |
| 9027 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9028 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9029 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9030 | .rpc_call_done = nfs41_free_stateid_done, |
| 9031 | .rpc_release = nfs41_free_stateid_release, |
| 9032 | }; |
| 9033 | |
| 9034 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9035 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9036 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9037 | bool privileged) |
| 9038 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9039 | struct rpc_message msg = { |
| 9040 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9041 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9042 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9043 | struct rpc_task_setup task_setup = { |
| 9044 | .rpc_client = server->client, |
| 9045 | .rpc_message = &msg, |
| 9046 | .callback_ops = &nfs41_free_stateid_ops, |
| 9047 | .flags = RPC_TASK_ASYNC, |
| 9048 | }; |
| 9049 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9050 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9051 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9052 | &task_setup.rpc_client, &msg); |
| 9053 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9054 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9055 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9056 | if (!data) |
| 9057 | return ERR_PTR(-ENOMEM); |
| 9058 | data->server = server; |
| 9059 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9060 | |
| 9061 | task_setup.callback_data = data; |
| 9062 | |
| 9063 | msg.rpc_argp = &data->args; |
| 9064 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9065 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9066 | if (privileged) |
| 9067 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9068 | |
| 9069 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9070 | } |
| 9071 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9072 | /** |
| 9073 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9074 | * |
| 9075 | * @server: server / transport on which to perform the operation |
| 9076 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9077 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9078 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9079 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9080 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9081 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9082 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9083 | const nfs4_stateid *stateid, |
| 9084 | struct rpc_cred *cred, |
| 9085 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9086 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9087 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9088 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9089 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9090 | if (IS_ERR(task)) |
| 9091 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9092 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9093 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9094 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9095 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9096 | static void |
| 9097 | 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] | 9098 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9099 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9100 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9101 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9102 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9103 | } |
| 9104 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9105 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9106 | const nfs4_stateid *s2) |
| 9107 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9108 | if (s1->type != s2->type) |
| 9109 | return false; |
| 9110 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9111 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9112 | return false; |
| 9113 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9114 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9115 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9116 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9117 | return true; |
| 9118 | |
| 9119 | return false; |
| 9120 | } |
| 9121 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9122 | #endif /* CONFIG_NFS_V4_1 */ |
| 9123 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9124 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9125 | const nfs4_stateid *s2) |
| 9126 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9127 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9128 | } |
| 9129 | |
| 9130 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9131 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9132 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9133 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9134 | .recover_open = nfs4_open_reclaim, |
| 9135 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9136 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9137 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9138 | }; |
| 9139 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9140 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9141 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9142 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9143 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9144 | .recover_open = nfs4_open_reclaim, |
| 9145 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9146 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9147 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9148 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9149 | }; |
| 9150 | #endif /* CONFIG_NFS_V4_1 */ |
| 9151 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9152 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9153 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9154 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9155 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9156 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9157 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9158 | }; |
| 9159 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9160 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9161 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9162 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9163 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9164 | .recover_open = nfs41_open_expired, |
| 9165 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9166 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9167 | }; |
| 9168 | #endif /* CONFIG_NFS_V4_1 */ |
| 9169 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9170 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9171 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9172 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9173 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9174 | }; |
| 9175 | |
| 9176 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9177 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9178 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9179 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9180 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9181 | }; |
| 9182 | #endif |
| 9183 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9184 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9185 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9186 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9187 | }; |
| 9188 | |
| 9189 | #if defined(CONFIG_NFS_V4_1) |
| 9190 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9191 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9192 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9193 | }; |
| 9194 | #endif /* CONFIG_NFS_V4_1 */ |
| 9195 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9196 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9197 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9198 | .init_caps = NFS_CAP_READDIRPLUS |
| 9199 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9200 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9201 | .init_client = nfs40_init_client, |
| 9202 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9203 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9204 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9205 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9206 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9207 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9208 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9209 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9210 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9211 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9212 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9213 | }; |
| 9214 | |
| 9215 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9216 | static struct nfs_seqid * |
| 9217 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9218 | { |
| 9219 | return NULL; |
| 9220 | } |
| 9221 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9222 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9223 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9224 | .init_caps = NFS_CAP_READDIRPLUS |
| 9225 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9226 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9227 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9228 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9229 | .init_client = nfs41_init_client, |
| 9230 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9231 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9232 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9233 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9234 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9235 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9236 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9237 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9238 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9239 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9240 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9241 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9242 | }; |
| 9243 | #endif |
| 9244 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9245 | #if defined(CONFIG_NFS_V4_2) |
| 9246 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9247 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9248 | .init_caps = NFS_CAP_READDIRPLUS |
| 9249 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9250 | | NFS_CAP_POSIX_LOCK |
| 9251 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9252 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9253 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9254 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9255 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9256 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9257 | | NFS_CAP_LAYOUTSTATS |
| 9258 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9259 | .init_client = nfs41_init_client, |
| 9260 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9261 | .match_stateid = nfs41_match_stateid, |
| 9262 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9263 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9264 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9265 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9266 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9267 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9268 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9269 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9270 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9271 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9272 | }; |
| 9273 | #endif |
| 9274 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9275 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9276 | [0] = &nfs_v4_0_minor_ops, |
| 9277 | #if defined(CONFIG_NFS_V4_1) |
| 9278 | [1] = &nfs_v4_1_minor_ops, |
| 9279 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9280 | #if defined(CONFIG_NFS_V4_2) |
| 9281 | [2] = &nfs_v4_2_minor_ops, |
| 9282 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9283 | }; |
| 9284 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9285 | 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] | 9286 | { |
| 9287 | ssize_t error, error2; |
| 9288 | |
| 9289 | error = generic_listxattr(dentry, list, size); |
| 9290 | if (error < 0) |
| 9291 | return error; |
| 9292 | if (list) { |
| 9293 | list += error; |
| 9294 | size -= error; |
| 9295 | } |
| 9296 | |
| 9297 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9298 | if (error2 < 0) |
| 9299 | return error2; |
| 9300 | return error + error2; |
| 9301 | } |
| 9302 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9303 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9304 | .create = nfs_create, |
| 9305 | .lookup = nfs_lookup, |
| 9306 | .atomic_open = nfs_atomic_open, |
| 9307 | .link = nfs_link, |
| 9308 | .unlink = nfs_unlink, |
| 9309 | .symlink = nfs_symlink, |
| 9310 | .mkdir = nfs_mkdir, |
| 9311 | .rmdir = nfs_rmdir, |
| 9312 | .mknod = nfs_mknod, |
| 9313 | .rename = nfs_rename, |
| 9314 | .permission = nfs_permission, |
| 9315 | .getattr = nfs_getattr, |
| 9316 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9317 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9318 | }; |
| 9319 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9320 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9321 | .permission = nfs_permission, |
| 9322 | .getattr = nfs_getattr, |
| 9323 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9324 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9325 | }; |
| 9326 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9327 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9328 | .version = 4, /* protocol version */ |
| 9329 | .dentry_ops = &nfs4_dentry_operations, |
| 9330 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9331 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9332 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9333 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9334 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9335 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9336 | .getattr = nfs4_proc_getattr, |
| 9337 | .setattr = nfs4_proc_setattr, |
| 9338 | .lookup = nfs4_proc_lookup, |
| 9339 | .access = nfs4_proc_access, |
| 9340 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9341 | .create = nfs4_proc_create, |
| 9342 | .remove = nfs4_proc_remove, |
| 9343 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9344 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9345 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9346 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9347 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9348 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9349 | .link = nfs4_proc_link, |
| 9350 | .symlink = nfs4_proc_symlink, |
| 9351 | .mkdir = nfs4_proc_mkdir, |
| 9352 | .rmdir = nfs4_proc_remove, |
| 9353 | .readdir = nfs4_proc_readdir, |
| 9354 | .mknod = nfs4_proc_mknod, |
| 9355 | .statfs = nfs4_proc_statfs, |
| 9356 | .fsinfo = nfs4_proc_fsinfo, |
| 9357 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9358 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9359 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9360 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9361 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9362 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9363 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9364 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9365 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9366 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9367 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9368 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9369 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9370 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9371 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9372 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9373 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9374 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9375 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9376 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9377 | .create_server = nfs4_create_server, |
| 9378 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9379 | }; |
| 9380 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9381 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9382 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9383 | .list = nfs4_xattr_list_nfs4_acl, |
| 9384 | .get = nfs4_xattr_get_nfs4_acl, |
| 9385 | .set = nfs4_xattr_set_nfs4_acl, |
| 9386 | }; |
| 9387 | |
| 9388 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9389 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9390 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9391 | &nfs4_xattr_nfs4_label_handler, |
| 9392 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9393 | NULL |
| 9394 | }; |
| 9395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9396 | /* |
| 9397 | * Local variables: |
| 9398 | * c-basic-offset: 8 |
| 9399 | * End: |
| 9400 | */ |