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: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 758 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 759 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 760 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 761 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 762 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 763 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 764 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 765 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 766 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 767 | case 1: |
| 768 | /* |
| 769 | * sr_status remains 1 if an RPC level error occurred. |
| 770 | * The server may or may not have processed the sequence |
| 771 | * operation.. |
| 772 | * Mark the slot as having hosted an interrupted RPC call. |
| 773 | */ |
| 774 | slot->interrupted = 1; |
| 775 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 776 | case -NFS4ERR_DELAY: |
| 777 | /* The server detected a resend of the RPC call and |
| 778 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 779 | * of RFC5661. |
| 780 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 781 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 782 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 783 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 784 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 785 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 786 | case -NFS4ERR_BADSLOT: |
| 787 | /* |
| 788 | * The slot id we used was probably retired. Try again |
| 789 | * using a different slot id. |
| 790 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | goto retry_nowait; |
| 792 | case -NFS4ERR_SEQ_MISORDERED: |
| 793 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 794 | * Was the last operation on this sequence interrupted? |
| 795 | * If so, retry after bumping the sequence number. |
| 796 | */ |
| 797 | if (interrupted) { |
| 798 | ++slot->seq_nr; |
| 799 | goto retry_nowait; |
| 800 | } |
| 801 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 802 | * Could this slot have been previously retired? |
| 803 | * If so, then the server may be expecting seq_nr = 1! |
| 804 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 805 | if (slot->seq_nr != 1) { |
| 806 | slot->seq_nr = 1; |
| 807 | goto retry_nowait; |
| 808 | } |
| 809 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 810 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 811 | ++slot->seq_nr; |
| 812 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 813 | default: |
| 814 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 815 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 816 | } |
| 817 | out: |
| 818 | /* The session may be reset by one of the error handlers. */ |
| 819 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 820 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 821 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 822 | retry_nowait: |
| 823 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 824 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 825 | task->tk_status = 0; |
| 826 | ret = 0; |
| 827 | } |
| 828 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 830 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | goto out; |
| 832 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 833 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 834 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 835 | |
| 836 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 837 | { |
| 838 | if (!nfs41_sequence_process(task, res)) |
| 839 | return 0; |
| 840 | if (res->sr_slot != NULL) |
| 841 | nfs41_sequence_free_slot(res); |
| 842 | return 1; |
| 843 | |
| 844 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 845 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 846 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 847 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 848 | { |
| 849 | if (res->sr_slot == NULL) |
| 850 | return 1; |
| 851 | if (res->sr_slot->table->session != NULL) |
| 852 | return nfs41_sequence_process(task, res); |
| 853 | return nfs40_sequence_done(task, res); |
| 854 | } |
| 855 | |
| 856 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 857 | { |
| 858 | if (res->sr_slot != NULL) { |
| 859 | if (res->sr_slot->table->session != NULL) |
| 860 | nfs41_sequence_free_slot(res); |
| 861 | else |
| 862 | nfs40_sequence_free_slot(res); |
| 863 | } |
| 864 | } |
| 865 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 866 | 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] | 867 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 868 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 869 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 870 | if (!res->sr_slot->table->session) |
| 871 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 872 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 873 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 874 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 875 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 876 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | struct nfs4_sequence_args *args, |
| 878 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 879 | struct rpc_task *task) |
| 880 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 881 | struct nfs4_slot *slot; |
| 882 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 883 | |
| 884 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 885 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 886 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 887 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 888 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | tbl = &session->fc_slot_table; |
| 890 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 891 | task->tk_timeout = 0; |
| 892 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 893 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 894 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 895 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 896 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 897 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 898 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 899 | } |
| 900 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 901 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 902 | if (IS_ERR(slot)) { |
| 903 | /* If out of memory, try again in 1/4 second */ |
| 904 | if (slot == ERR_PTR(-ENOMEM)) |
| 905 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 906 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 907 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 908 | } |
| 909 | spin_unlock(&tbl->slot_tbl_lock); |
| 910 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 911 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 912 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 913 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 914 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 915 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 916 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 917 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 918 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 919 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 920 | /* |
| 921 | * sr_status is only set in decode_sequence, and so will remain |
| 922 | * set to 1 if an rpc level failure occurs. |
| 923 | */ |
| 924 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 925 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 926 | out_success: |
| 927 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 928 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 929 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 930 | /* Privileged tasks are queued with top priority */ |
| 931 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 932 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 933 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 934 | else |
| 935 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 936 | spin_unlock(&tbl->slot_tbl_lock); |
| 937 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 938 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 939 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 941 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 942 | struct nfs4_sequence_args *args, |
| 943 | struct nfs4_sequence_res *res, |
| 944 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 945 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 946 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | int ret = 0; |
| 948 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 949 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 950 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 951 | args, res, task); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 952 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 953 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 954 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 955 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 956 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 957 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 958 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 959 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 960 | return ret; |
| 961 | } |
| 962 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 963 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 964 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 965 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 966 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 967 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 968 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 969 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 970 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 971 | } |
| 972 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 973 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 974 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 975 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 976 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 977 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 978 | } |
| 979 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 980 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 981 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 983 | }; |
| 984 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 985 | #else /* !CONFIG_NFS_V4_1 */ |
| 986 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 987 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 988 | struct nfs4_sequence_args *args, |
| 989 | struct nfs4_sequence_res *res, |
| 990 | struct rpc_task *task) |
| 991 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 992 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 993 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 994 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 995 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 996 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 997 | { |
| 998 | return nfs40_sequence_done(task, res); |
| 999 | } |
| 1000 | |
| 1001 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1002 | { |
| 1003 | if (res->sr_slot != NULL) |
| 1004 | nfs40_sequence_free_slot(res); |
| 1005 | } |
| 1006 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1007 | int nfs4_sequence_done(struct rpc_task *task, |
| 1008 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1009 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1010 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1011 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1012 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1013 | |
| 1014 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1015 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1016 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1017 | { |
| 1018 | struct nfs4_call_sync_data *data = calldata; |
| 1019 | nfs4_setup_sequence(data->seq_server, |
| 1020 | data->seq_args, data->seq_res, task); |
| 1021 | } |
| 1022 | |
| 1023 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1024 | { |
| 1025 | struct nfs4_call_sync_data *data = calldata; |
| 1026 | nfs4_sequence_done(task, data->seq_res); |
| 1027 | } |
| 1028 | |
| 1029 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1030 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1031 | .rpc_call_done = nfs40_call_sync_done, |
| 1032 | }; |
| 1033 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1034 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1035 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1039 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1040 | int ret; |
| 1041 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1042 | struct nfs_client *clp = server->nfs_client; |
| 1043 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1044 | .seq_server = server, |
| 1045 | .seq_args = args, |
| 1046 | .seq_res = res, |
| 1047 | }; |
| 1048 | struct rpc_task_setup task_setup = { |
| 1049 | .rpc_client = clnt, |
| 1050 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1051 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | .callback_data = &data |
| 1053 | }; |
| 1054 | |
| 1055 | task = rpc_run_task(&task_setup); |
| 1056 | if (IS_ERR(task)) |
| 1057 | ret = PTR_ERR(task); |
| 1058 | else { |
| 1059 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1060 | rpc_put_task(task); |
| 1061 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1062 | return ret; |
| 1063 | } |
| 1064 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1065 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1066 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1067 | struct rpc_message *msg, |
| 1068 | struct nfs4_sequence_args *args, |
| 1069 | struct nfs4_sequence_res *res, |
| 1070 | int cache_reply) |
| 1071 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1072 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1073 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
| 1076 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1077 | { |
| 1078 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1079 | |
| 1080 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1081 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1082 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1084 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1085 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1086 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | spin_unlock(&dir->i_lock); |
| 1088 | } |
| 1089 | |
| 1090 | struct nfs4_opendata { |
| 1091 | struct kref kref; |
| 1092 | struct nfs_openargs o_arg; |
| 1093 | struct nfs_openres o_res; |
| 1094 | struct nfs_open_confirmargs c_arg; |
| 1095 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1096 | struct nfs4_string owner_name; |
| 1097 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1098 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1100 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1102 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | struct nfs4_state_owner *owner; |
| 1104 | struct nfs4_state *state; |
| 1105 | struct iattr attrs; |
| 1106 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1107 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1108 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1109 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1110 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | int cancelled; |
| 1112 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1113 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1114 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1115 | int err, struct nfs4_exception *exception) |
| 1116 | { |
| 1117 | if (err != -EINVAL) |
| 1118 | return false; |
| 1119 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1120 | return false; |
| 1121 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1122 | exception->retry = 1; |
| 1123 | return true; |
| 1124 | } |
| 1125 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1126 | static u32 |
| 1127 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1128 | fmode_t fmode, int openflags) |
| 1129 | { |
| 1130 | u32 res = 0; |
| 1131 | |
| 1132 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1133 | case FMODE_READ: |
| 1134 | res = NFS4_SHARE_ACCESS_READ; |
| 1135 | break; |
| 1136 | case FMODE_WRITE: |
| 1137 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1138 | break; |
| 1139 | case FMODE_READ|FMODE_WRITE: |
| 1140 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1141 | } |
| 1142 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1143 | goto out; |
| 1144 | /* Want no delegation if we're using O_DIRECT */ |
| 1145 | if (openflags & O_DIRECT) |
| 1146 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1147 | out: |
| 1148 | return res; |
| 1149 | } |
| 1150 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1151 | static enum open_claim_type4 |
| 1152 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1153 | enum open_claim_type4 claim) |
| 1154 | { |
| 1155 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1156 | return claim; |
| 1157 | switch (claim) { |
| 1158 | default: |
| 1159 | return claim; |
| 1160 | case NFS4_OPEN_CLAIM_FH: |
| 1161 | return NFS4_OPEN_CLAIM_NULL; |
| 1162 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1163 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1164 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1165 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1166 | } |
| 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
| 1169 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1170 | { |
| 1171 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1172 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | p->o_res.seqid = p->o_arg.seqid; |
| 1174 | p->c_res.seqid = p->c_arg.seqid; |
| 1175 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1176 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1178 | 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] | 1179 | } |
| 1180 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1181 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1182 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1183 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1184 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1185 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1186 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1188 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1189 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1190 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1191 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1192 | struct nfs4_opendata *p; |
| 1193 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1194 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | if (p == NULL) |
| 1196 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1197 | |
| 1198 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1199 | if (IS_ERR(p->f_label)) |
| 1200 | goto err_free_p; |
| 1201 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1202 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1203 | if (IS_ERR(p->a_label)) |
| 1204 | goto err_free_f; |
| 1205 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1206 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1207 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1208 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1209 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1210 | nfs_sb_active(dentry->d_sb); |
| 1211 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1212 | p->dir = parent; |
| 1213 | p->owner = sp; |
| 1214 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | p->o_arg.open_flags = flags; |
| 1216 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1217 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1218 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1219 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1220 | * will return permission denied for all bits until close */ |
| 1221 | if (!(flags & O_EXCL)) { |
| 1222 | /* ask server to check for all possible rights as results |
| 1223 | * are cached */ |
| 1224 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1225 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1226 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1227 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1228 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1229 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1230 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1231 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1232 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1233 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1234 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1235 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1236 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1237 | case NFS4_OPEN_CLAIM_NULL: |
| 1238 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1239 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1240 | p->o_arg.fh = NFS_FH(dir); |
| 1241 | break; |
| 1242 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1243 | case NFS4_OPEN_CLAIM_FH: |
| 1244 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1245 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1246 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1247 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1248 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1249 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1250 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1251 | p->o_arg.u.attrs = &p->attrs; |
| 1252 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1253 | |
| 1254 | verf[0] = jiffies; |
| 1255 | verf[1] = current->pid; |
| 1256 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1257 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1259 | p->c_arg.fh = &p->o_res.fh; |
| 1260 | p->c_arg.stateid = &p->o_res.stateid; |
| 1261 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1262 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1263 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1264 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1265 | |
| 1266 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1267 | nfs4_label_free(p->a_label); |
| 1268 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1269 | nfs4_label_free(p->f_label); |
| 1270 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | kfree(p); |
| 1272 | err: |
| 1273 | dput(parent); |
| 1274 | return NULL; |
| 1275 | } |
| 1276 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1279 | struct nfs4_opendata *p = container_of(kref, |
| 1280 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1281 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1282 | |
| 1283 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1284 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1285 | if (p->state != NULL) |
| 1286 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1287 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1288 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1289 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1290 | nfs4_label_free(p->f_label); |
| 1291 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1292 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1293 | dput(p->dentry); |
| 1294 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1295 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1296 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1297 | kfree(p); |
| 1298 | } |
| 1299 | |
| 1300 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1301 | { |
| 1302 | if (p != NULL) |
| 1303 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1306 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1307 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1308 | int ret; |
| 1309 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1310 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1311 | return ret; |
| 1312 | } |
| 1313 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1314 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1315 | fmode_t fmode) |
| 1316 | { |
| 1317 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1318 | case FMODE_READ|FMODE_WRITE: |
| 1319 | return state->n_rdwr != 0; |
| 1320 | case FMODE_WRITE: |
| 1321 | return state->n_wronly != 0; |
| 1322 | case FMODE_READ: |
| 1323 | return state->n_rdonly != 0; |
| 1324 | } |
| 1325 | WARN_ON_ONCE(1); |
| 1326 | return false; |
| 1327 | } |
| 1328 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1329 | 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] | 1330 | { |
| 1331 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1332 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1333 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1334 | goto out; |
| 1335 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1336 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1337 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1338 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1339 | break; |
| 1340 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1341 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1342 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1343 | break; |
| 1344 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1345 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1346 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1347 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1349 | return ret; |
| 1350 | } |
| 1351 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1352 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1353 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1354 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1355 | if (delegation == NULL) |
| 1356 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1358 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1359 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1360 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1361 | switch (claim) { |
| 1362 | case NFS4_OPEN_CLAIM_NULL: |
| 1363 | case NFS4_OPEN_CLAIM_FH: |
| 1364 | break; |
| 1365 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1366 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1367 | break; |
| 1368 | default: |
| 1369 | return 0; |
| 1370 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1371 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1372 | return 1; |
| 1373 | } |
| 1374 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1375 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1376 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1377 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1378 | case FMODE_WRITE: |
| 1379 | state->n_wronly++; |
| 1380 | break; |
| 1381 | case FMODE_READ: |
| 1382 | state->n_rdonly++; |
| 1383 | break; |
| 1384 | case FMODE_READ|FMODE_WRITE: |
| 1385 | state->n_rdwr++; |
| 1386 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1387 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1390 | 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] | 1391 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1392 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1393 | bool need_recover = false; |
| 1394 | |
| 1395 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1396 | need_recover = true; |
| 1397 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1398 | need_recover = true; |
| 1399 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1400 | need_recover = true; |
| 1401 | if (need_recover) |
| 1402 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1403 | } |
| 1404 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1405 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1406 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1407 | { |
| 1408 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1409 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1410 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1411 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1412 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1413 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1414 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1415 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1416 | return true; |
| 1417 | return false; |
| 1418 | } |
| 1419 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1420 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1421 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1422 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1423 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1424 | if (state->n_wronly) |
| 1425 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1426 | if (state->n_rdonly) |
| 1427 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1428 | if (state->n_rdwr) |
| 1429 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1430 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1431 | } |
| 1432 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1433 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1434 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1435 | nfs4_stateid *stateid, fmode_t fmode) |
| 1436 | { |
| 1437 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1438 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1439 | case FMODE_WRITE: |
| 1440 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1441 | break; |
| 1442 | case FMODE_READ: |
| 1443 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1444 | break; |
| 1445 | case 0: |
| 1446 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1447 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1448 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1449 | } |
| 1450 | if (stateid == NULL) |
| 1451 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1452 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1453 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1454 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1455 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1456 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1457 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1458 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1459 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1460 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1461 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1462 | } |
| 1463 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1464 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1465 | nfs4_stateid *arg_stateid, |
| 1466 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1467 | { |
| 1468 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1469 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1470 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1471 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1472 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1473 | } |
| 1474 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1475 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1476 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1477 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1478 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1479 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1480 | case FMODE_READ: |
| 1481 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1482 | break; |
| 1483 | case FMODE_WRITE: |
| 1484 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1485 | break; |
| 1486 | case FMODE_READ|FMODE_WRITE: |
| 1487 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1488 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1489 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1490 | return; |
| 1491 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1492 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1493 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1496 | static void __update_open_stateid(struct nfs4_state *state, |
| 1497 | const nfs4_stateid *open_stateid, |
| 1498 | const nfs4_stateid *deleg_stateid, |
| 1499 | fmode_t fmode, |
| 1500 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1502 | /* |
| 1503 | * Protect the call to nfs4_state_set_mode_locked and |
| 1504 | * serialise the stateid update |
| 1505 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1506 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1507 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1508 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1509 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1510 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1511 | } |
| 1512 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1513 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1514 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1515 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1516 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1519 | static int update_open_stateid(struct nfs4_state *state, |
| 1520 | const nfs4_stateid *open_stateid, |
| 1521 | const nfs4_stateid *delegation, |
| 1522 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1523 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1524 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1525 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1526 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1527 | struct nfs_delegation *deleg_cur; |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1528 | nfs4_stateid freeme = {0}; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1529 | int ret = 0; |
| 1530 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1531 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1532 | |
| 1533 | rcu_read_lock(); |
| 1534 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1535 | if (deleg_cur == NULL) |
| 1536 | goto no_delegation; |
| 1537 | |
| 1538 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1539 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1540 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1542 | goto no_delegation_unlock; |
| 1543 | |
| 1544 | if (delegation == NULL) |
| 1545 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1546 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1547 | goto no_delegation_unlock; |
| 1548 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1549 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1550 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1551 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1552 | ret = 1; |
| 1553 | no_delegation_unlock: |
| 1554 | spin_unlock(&deleg_cur->lock); |
| 1555 | no_delegation: |
| 1556 | rcu_read_unlock(); |
| 1557 | |
| 1558 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1559 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1560 | ret = 1; |
| 1561 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1562 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1563 | nfs4_schedule_state_manager(clp); |
| 1564 | if (freeme.type != 0) |
| 1565 | nfs4_test_and_free_stateid(server, &freeme, |
| 1566 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1567 | |
| 1568 | return ret; |
| 1569 | } |
| 1570 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1571 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1572 | const nfs4_stateid *stateid) |
| 1573 | { |
| 1574 | struct nfs4_state *state = lsp->ls_state; |
| 1575 | bool ret = false; |
| 1576 | |
| 1577 | spin_lock(&state->state_lock); |
| 1578 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1579 | goto out_noupdate; |
| 1580 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1581 | goto out_noupdate; |
| 1582 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1583 | ret = true; |
| 1584 | out_noupdate: |
| 1585 | spin_unlock(&state->state_lock); |
| 1586 | return ret; |
| 1587 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1588 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1589 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1590 | { |
| 1591 | struct nfs_delegation *delegation; |
| 1592 | |
| 1593 | rcu_read_lock(); |
| 1594 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1595 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1596 | rcu_read_unlock(); |
| 1597 | return; |
| 1598 | } |
| 1599 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1600 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1601 | } |
| 1602 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1603 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1604 | { |
| 1605 | struct nfs4_state *state = opendata->state; |
| 1606 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1607 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1608 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1609 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1610 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1611 | nfs4_stateid stateid; |
| 1612 | int ret = -EAGAIN; |
| 1613 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1614 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1615 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1616 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1617 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1618 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1619 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1620 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1621 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1622 | rcu_read_lock(); |
| 1623 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1624 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1625 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1626 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1627 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1628 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1629 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1630 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1631 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1632 | if (!opendata->is_recover) { |
| 1633 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1634 | if (ret != 0) |
| 1635 | goto out; |
| 1636 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1637 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1638 | |
| 1639 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1640 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1641 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1642 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1643 | out: |
| 1644 | return ERR_PTR(ret); |
| 1645 | out_return_state: |
| 1646 | atomic_inc(&state->count); |
| 1647 | return state; |
| 1648 | } |
| 1649 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1650 | static void |
| 1651 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1652 | { |
| 1653 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1654 | struct nfs_delegation *delegation; |
| 1655 | int delegation_flags = 0; |
| 1656 | |
| 1657 | rcu_read_lock(); |
| 1658 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1659 | if (delegation) |
| 1660 | delegation_flags = delegation->flags; |
| 1661 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1662 | switch (data->o_arg.claim) { |
| 1663 | default: |
| 1664 | break; |
| 1665 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1666 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1667 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1668 | "returning a delegation for " |
| 1669 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1670 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1671 | return; |
| 1672 | } |
| 1673 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1674 | nfs_inode_set_delegation(state->inode, |
| 1675 | data->owner->so_cred, |
| 1676 | &data->o_res); |
| 1677 | else |
| 1678 | nfs_inode_reclaim_delegation(state->inode, |
| 1679 | data->owner->so_cred, |
| 1680 | &data->o_res); |
| 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1685 | * and update the nfs4_state. |
| 1686 | */ |
| 1687 | static struct nfs4_state * |
| 1688 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1689 | { |
| 1690 | struct inode *inode = data->state->inode; |
| 1691 | struct nfs4_state *state = data->state; |
| 1692 | int ret; |
| 1693 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1694 | if (!data->rpc_done) { |
| 1695 | if (data->rpc_status) { |
| 1696 | ret = data->rpc_status; |
| 1697 | goto err; |
| 1698 | } |
| 1699 | /* cached opens have already been processed */ |
| 1700 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1701 | } |
| 1702 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1703 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1704 | if (ret) |
| 1705 | goto err; |
| 1706 | |
| 1707 | if (data->o_res.delegation_type != 0) |
| 1708 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1709 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1710 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1711 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1712 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1713 | |
| 1714 | return state; |
| 1715 | err: |
| 1716 | return ERR_PTR(ret); |
| 1717 | |
| 1718 | } |
| 1719 | |
| 1720 | static struct nfs4_state * |
| 1721 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1722 | { |
| 1723 | struct inode *inode; |
| 1724 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1725 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1726 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1727 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1728 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1729 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1730 | goto out; |
| 1731 | } |
| 1732 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1733 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1734 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1735 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1736 | 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] | 1737 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1738 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1739 | goto err; |
| 1740 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1741 | state = nfs4_get_open_state(inode, data->owner); |
| 1742 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1743 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1744 | if (data->o_res.delegation_type != 0) |
| 1745 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1746 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1747 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1748 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1749 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1750 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1751 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1752 | err_put_inode: |
| 1753 | iput(inode); |
| 1754 | err: |
| 1755 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1756 | } |
| 1757 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1758 | static struct nfs4_state * |
| 1759 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1760 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1761 | struct nfs4_state *ret; |
| 1762 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1763 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1764 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1765 | else |
| 1766 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1767 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1768 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1769 | } |
| 1770 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1771 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1772 | { |
| 1773 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1774 | struct nfs_open_context *ctx; |
| 1775 | |
| 1776 | spin_lock(&state->inode->i_lock); |
| 1777 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1778 | if (ctx->state != state) |
| 1779 | continue; |
| 1780 | get_nfs_open_context(ctx); |
| 1781 | spin_unlock(&state->inode->i_lock); |
| 1782 | return ctx; |
| 1783 | } |
| 1784 | spin_unlock(&state->inode->i_lock); |
| 1785 | return ERR_PTR(-ENOENT); |
| 1786 | } |
| 1787 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1788 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1789 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1790 | { |
| 1791 | struct nfs4_opendata *opendata; |
| 1792 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1793 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1794 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1795 | if (opendata == NULL) |
| 1796 | return ERR_PTR(-ENOMEM); |
| 1797 | opendata->state = state; |
| 1798 | atomic_inc(&state->count); |
| 1799 | return opendata; |
| 1800 | } |
| 1801 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1802 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1803 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1804 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1805 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1806 | int ret; |
| 1807 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1808 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1809 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1810 | opendata->o_arg.open_flags = 0; |
| 1811 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1812 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1813 | NFS_SB(opendata->dentry->d_sb), |
| 1814 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1815 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1816 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1817 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1818 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1819 | if (ret != 0) |
| 1820 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1821 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1822 | if (IS_ERR(newstate)) |
| 1823 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1824 | if (newstate != opendata->state) |
| 1825 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1826 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1827 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1831 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1832 | int ret; |
| 1833 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1834 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1835 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1836 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1837 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1838 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1839 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1840 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1841 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1842 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1843 | if (ret != 0) |
| 1844 | return ret; |
| 1845 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1846 | if (ret != 0) |
| 1847 | return ret; |
| 1848 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1849 | if (ret != 0) |
| 1850 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1851 | /* |
| 1852 | * We may have performed cached opens for all three recoveries. |
| 1853 | * Check if we need to update the current stateid. |
| 1854 | */ |
| 1855 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1856 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1857 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1858 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1859 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1860 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1861 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1862 | return 0; |
| 1863 | } |
| 1864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | /* |
| 1866 | * OPEN_RECLAIM: |
| 1867 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1869 | 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] | 1870 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1871 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1872 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1873 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | int status; |
| 1875 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1876 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1877 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1878 | if (IS_ERR(opendata)) |
| 1879 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1880 | rcu_read_lock(); |
| 1881 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1882 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1883 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1884 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1885 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1886 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1887 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | return status; |
| 1889 | } |
| 1890 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1891 | 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] | 1892 | { |
| 1893 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1894 | struct nfs4_exception exception = { }; |
| 1895 | int err; |
| 1896 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1897 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1898 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1899 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1900 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1901 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1902 | break; |
| 1903 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | } while (exception.retry); |
| 1905 | return err; |
| 1906 | } |
| 1907 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1908 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1909 | { |
| 1910 | struct nfs_open_context *ctx; |
| 1911 | int ret; |
| 1912 | |
| 1913 | ctx = nfs4_state_find_open_context(state); |
| 1914 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1915 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1916 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1917 | put_nfs_open_context(ctx); |
| 1918 | return ret; |
| 1919 | } |
| 1920 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1921 | 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] | 1922 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1923 | switch (err) { |
| 1924 | default: |
| 1925 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1926 | "%d.\n", __func__, err); |
| 1927 | case 0: |
| 1928 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1929 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1930 | case -ESTALE: |
| 1931 | break; |
| 1932 | case -NFS4ERR_BADSESSION: |
| 1933 | case -NFS4ERR_BADSLOT: |
| 1934 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1935 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1936 | case -NFS4ERR_DEADSESSION: |
| 1937 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1938 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1939 | return -EAGAIN; |
| 1940 | case -NFS4ERR_STALE_CLIENTID: |
| 1941 | case -NFS4ERR_STALE_STATEID: |
| 1942 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1943 | /* Don't recall a delegation if it was lost */ |
| 1944 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1945 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1946 | case -NFS4ERR_MOVED: |
| 1947 | nfs4_schedule_migration_recovery(server); |
| 1948 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1949 | case -NFS4ERR_LEASE_MOVED: |
| 1950 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1951 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1952 | case -NFS4ERR_DELEG_REVOKED: |
| 1953 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1954 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1955 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1956 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1957 | nfs_inode_find_state_and_recover(state->inode, |
| 1958 | stateid); |
| 1959 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1960 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1961 | case -NFS4ERR_DELAY: |
| 1962 | case -NFS4ERR_GRACE: |
| 1963 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1964 | ssleep(1); |
| 1965 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1966 | case -ENOMEM: |
| 1967 | case -NFS4ERR_DENIED: |
| 1968 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1969 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1970 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | return err; |
| 1972 | } |
| 1973 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1974 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1975 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1976 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1977 | { |
| 1978 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1979 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1980 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1981 | |
| 1982 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1983 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1984 | if (IS_ERR(opendata)) |
| 1985 | return PTR_ERR(opendata); |
| 1986 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1987 | write_seqlock(&state->seqlock); |
| 1988 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1989 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1990 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1991 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1992 | case FMODE_READ|FMODE_WRITE: |
| 1993 | case FMODE_WRITE: |
| 1994 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1995 | if (err) |
| 1996 | break; |
| 1997 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1998 | if (err) |
| 1999 | break; |
| 2000 | case FMODE_READ: |
| 2001 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2002 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2003 | nfs4_opendata_put(opendata); |
| 2004 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2005 | } |
| 2006 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2007 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2008 | { |
| 2009 | struct nfs4_opendata *data = calldata; |
| 2010 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2011 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2012 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2013 | } |
| 2014 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2015 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2016 | { |
| 2017 | struct nfs4_opendata *data = calldata; |
| 2018 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2019 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2020 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2021 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2022 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2023 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2024 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2025 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2026 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2027 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | static void nfs4_open_confirm_release(void *calldata) |
| 2031 | { |
| 2032 | struct nfs4_opendata *data = calldata; |
| 2033 | struct nfs4_state *state = NULL; |
| 2034 | |
| 2035 | /* If this request hasn't been cancelled, do nothing */ |
| 2036 | if (data->cancelled == 0) |
| 2037 | goto out_free; |
| 2038 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2039 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2040 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2041 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2042 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2043 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2044 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2045 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2049 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2050 | .rpc_call_done = nfs4_open_confirm_done, |
| 2051 | .rpc_release = nfs4_open_confirm_release, |
| 2052 | }; |
| 2053 | |
| 2054 | /* |
| 2055 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2056 | */ |
| 2057 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2058 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2059 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2060 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2061 | struct rpc_message msg = { |
| 2062 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2063 | .rpc_argp = &data->c_arg, |
| 2064 | .rpc_resp = &data->c_res, |
| 2065 | .rpc_cred = data->owner->so_cred, |
| 2066 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2067 | struct rpc_task_setup task_setup_data = { |
| 2068 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2069 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2070 | .callback_ops = &nfs4_open_confirm_ops, |
| 2071 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2072 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2073 | .flags = RPC_TASK_ASYNC, |
| 2074 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | int status; |
| 2076 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2077 | 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] | 2078 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2079 | data->rpc_done = 0; |
| 2080 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2081 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2082 | if (data->is_recover) |
| 2083 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2084 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2085 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2086 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2087 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2088 | if (status != 0) { |
| 2089 | data->cancelled = 1; |
| 2090 | smp_wmb(); |
| 2091 | } else |
| 2092 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2093 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | return status; |
| 2095 | } |
| 2096 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2097 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2099 | struct nfs4_opendata *data = calldata; |
| 2100 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2101 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2102 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2103 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2104 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2105 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2106 | /* |
| 2107 | * Check if we still need to send an OPEN call, or if we can use |
| 2108 | * a delegation instead. |
| 2109 | */ |
| 2110 | if (data->state != NULL) { |
| 2111 | struct nfs_delegation *delegation; |
| 2112 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2113 | 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] | 2114 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2115 | rcu_read_lock(); |
| 2116 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2117 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2118 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2119 | rcu_read_unlock(); |
| 2120 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2121 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2122 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2123 | switch (claim) { |
| 2124 | default: |
| 2125 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2126 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2127 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2128 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2129 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2130 | case NFS4_OPEN_CLAIM_FH: |
| 2131 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2132 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2133 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2134 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2135 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2136 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2137 | &data->o_res.seq_res, |
| 2138 | task) != 0) |
| 2139 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2140 | |
| 2141 | /* Set the create mode (note dependency on the session type) */ |
| 2142 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2143 | if (data->o_arg.open_flags & O_EXCL) { |
| 2144 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2145 | if (nfs4_has_persistent_session(clp)) |
| 2146 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2147 | else if (clp->cl_mvops->minor_version > 0) |
| 2148 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2149 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2150 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2151 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2152 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2153 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2154 | out_no_action: |
| 2155 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2156 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2157 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2161 | { |
| 2162 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2164 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2165 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2166 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2167 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2168 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2169 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2170 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2171 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2172 | case S_IFREG: |
| 2173 | break; |
| 2174 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2175 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2176 | break; |
| 2177 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2178 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2179 | break; |
| 2180 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2181 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2182 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2183 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2184 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2185 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2186 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2187 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2188 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2189 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2190 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | static void nfs4_open_release(void *calldata) |
| 2192 | { |
| 2193 | struct nfs4_opendata *data = calldata; |
| 2194 | struct nfs4_state *state = NULL; |
| 2195 | |
| 2196 | /* If this request hasn't been cancelled, do nothing */ |
| 2197 | if (data->cancelled == 0) |
| 2198 | goto out_free; |
| 2199 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2200 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2201 | goto out_free; |
| 2202 | /* In case we need an open_confirm, no cleanup! */ |
| 2203 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2204 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2205 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2206 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2207 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2208 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2209 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2213 | .rpc_call_prepare = nfs4_open_prepare, |
| 2214 | .rpc_call_done = nfs4_open_done, |
| 2215 | .rpc_release = nfs4_open_release, |
| 2216 | }; |
| 2217 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2218 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2219 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2220 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2221 | struct nfs_server *server = NFS_SERVER(dir); |
| 2222 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2223 | struct nfs_openres *o_res = &data->o_res; |
| 2224 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2225 | struct rpc_message msg = { |
| 2226 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2227 | .rpc_argp = o_arg, |
| 2228 | .rpc_resp = o_res, |
| 2229 | .rpc_cred = data->owner->so_cred, |
| 2230 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2231 | struct rpc_task_setup task_setup_data = { |
| 2232 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2233 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2234 | .callback_ops = &nfs4_open_ops, |
| 2235 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2236 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2237 | .flags = RPC_TASK_ASYNC, |
| 2238 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2239 | int status; |
| 2240 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2241 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2242 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2243 | data->rpc_done = 0; |
| 2244 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2245 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2246 | data->is_recover = 0; |
| 2247 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2248 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2249 | data->is_recover = 1; |
| 2250 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2251 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2252 | if (IS_ERR(task)) |
| 2253 | return PTR_ERR(task); |
| 2254 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2255 | if (status != 0) { |
| 2256 | data->cancelled = 1; |
| 2257 | smp_wmb(); |
| 2258 | } else |
| 2259 | status = data->rpc_status; |
| 2260 | rpc_put_task(task); |
| 2261 | |
| 2262 | return status; |
| 2263 | } |
| 2264 | |
| 2265 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2266 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2267 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2268 | struct nfs_openres *o_res = &data->o_res; |
| 2269 | int status; |
| 2270 | |
| 2271 | status = nfs4_run_open_task(data, 1); |
| 2272 | if (status != 0 || !data->rpc_done) |
| 2273 | return status; |
| 2274 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2275 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2276 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2277 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2278 | status = _nfs4_proc_open_confirm(data); |
| 2279 | if (status != 0) |
| 2280 | return status; |
| 2281 | } |
| 2282 | |
| 2283 | return status; |
| 2284 | } |
| 2285 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2286 | /* |
| 2287 | * Additional permission checks in order to distinguish between an |
| 2288 | * open for read, and an open for execute. This works around the |
| 2289 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2290 | * the same. |
| 2291 | * Note that in the non-execute case, we want to turn off permission |
| 2292 | * checking if we just created a new file (POSIX open() semantics). |
| 2293 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2294 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2295 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2296 | struct nfs4_state *state, fmode_t fmode, |
| 2297 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2298 | { |
| 2299 | struct nfs_access_entry cache; |
| 2300 | u32 mask; |
| 2301 | |
| 2302 | /* access call failed or for some reason the server doesn't |
| 2303 | * support any access modes -- defer access call until later */ |
| 2304 | if (opendata->o_res.access_supported == 0) |
| 2305 | return 0; |
| 2306 | |
| 2307 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2308 | /* |
| 2309 | * Use openflags to check for exec, because fmode won't |
| 2310 | * always have FMODE_EXEC set when file open for exec. |
| 2311 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2312 | if (openflags & __FMODE_EXEC) { |
| 2313 | /* ONLY check for exec rights */ |
| 2314 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2315 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2316 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2317 | |
| 2318 | cache.cred = cred; |
| 2319 | cache.jiffies = jiffies; |
| 2320 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2321 | nfs_access_add_cache(state->inode, &cache); |
| 2322 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2323 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2324 | return 0; |
| 2325 | |
| 2326 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2327 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2328 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2329 | } |
| 2330 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2331 | /* |
| 2332 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2333 | */ |
| 2334 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2335 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2336 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2337 | struct nfs_server *server = NFS_SERVER(dir); |
| 2338 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2339 | struct nfs_openres *o_res = &data->o_res; |
| 2340 | int status; |
| 2341 | |
| 2342 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2343 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2344 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2345 | if (status != 0) { |
| 2346 | if (status == -NFS4ERR_BADNAME && |
| 2347 | !(o_arg->open_flags & O_CREAT)) |
| 2348 | return -ENOENT; |
| 2349 | return status; |
| 2350 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2351 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2352 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2353 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2354 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2355 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2356 | if (o_arg->open_flags & O_EXCL) |
| 2357 | data->file_created = 1; |
| 2358 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2359 | data->file_created = 1; |
| 2360 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2361 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2362 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2364 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2366 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2369 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2370 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2373 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2374 | { |
| 2375 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2376 | } |
| 2377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | /* |
| 2379 | * OPEN_EXPIRED: |
| 2380 | * reclaim state on the server after a network partition. |
| 2381 | * Assumes caller holds the appropriate lock |
| 2382 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2383 | 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] | 2384 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2385 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2386 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2388 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2389 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2390 | if (IS_ERR(opendata)) |
| 2391 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2392 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2393 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2394 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2395 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2396 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2399 | 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] | 2400 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2401 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2402 | struct nfs4_exception exception = { }; |
| 2403 | int err; |
| 2404 | |
| 2405 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2406 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2407 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2408 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2409 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2410 | switch (err) { |
| 2411 | default: |
| 2412 | goto out; |
| 2413 | case -NFS4ERR_GRACE: |
| 2414 | case -NFS4ERR_DELAY: |
| 2415 | nfs4_handle_exception(server, err, &exception); |
| 2416 | err = 0; |
| 2417 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2418 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2419 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2420 | return err; |
| 2421 | } |
| 2422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2424 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2426 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2428 | ctx = nfs4_state_find_open_context(state); |
| 2429 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2430 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2431 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2432 | put_nfs_open_context(ctx); |
| 2433 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2436 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2437 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2438 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2439 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2440 | write_seqlock(&state->seqlock); |
| 2441 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2442 | write_sequnlock(&state->seqlock); |
| 2443 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2444 | } |
| 2445 | |
| 2446 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2447 | { |
| 2448 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2449 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2453 | { |
| 2454 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2455 | nfs40_clear_delegation_stateid(state); |
| 2456 | return nfs4_open_expired(sp, state); |
| 2457 | } |
| 2458 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2459 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2460 | nfs4_stateid *stateid, |
| 2461 | struct rpc_cred *cred) |
| 2462 | { |
| 2463 | return -NFS4ERR_BAD_STATEID; |
| 2464 | } |
| 2465 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2466 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2467 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2468 | nfs4_stateid *stateid, |
| 2469 | struct rpc_cred *cred) |
| 2470 | { |
| 2471 | int status; |
| 2472 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2473 | switch (stateid->type) { |
| 2474 | default: |
| 2475 | break; |
| 2476 | case NFS4_INVALID_STATEID_TYPE: |
| 2477 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2478 | return -NFS4ERR_BAD_STATEID; |
| 2479 | case NFS4_REVOKED_STATEID_TYPE: |
| 2480 | goto out_free; |
| 2481 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2482 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2483 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2484 | switch (status) { |
| 2485 | case -NFS4ERR_EXPIRED: |
| 2486 | case -NFS4ERR_ADMIN_REVOKED: |
| 2487 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2488 | break; |
| 2489 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2490 | return status; |
| 2491 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2492 | out_free: |
| 2493 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2494 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2495 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2496 | } |
| 2497 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2498 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2499 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2500 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2501 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2502 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2503 | struct rpc_cred *cred; |
| 2504 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2505 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2506 | /* Get the delegation credential for use by test/free_stateid */ |
| 2507 | rcu_read_lock(); |
| 2508 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2509 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2510 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2511 | return; |
| 2512 | } |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2513 | |
| 2514 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2515 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2516 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2517 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2518 | return; |
| 2519 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2520 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2521 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2522 | rcu_read_unlock(); |
| 2523 | return; |
| 2524 | } |
| 2525 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2526 | cred = get_rpccred(delegation->cred); |
| 2527 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2528 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2529 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2530 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2531 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2532 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2533 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2537 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2538 | * |
| 2539 | * @state: NFSv4 state for an inode |
| 2540 | * |
| 2541 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2542 | * Otherwise a negative NFS4ERR value is returned. |
| 2543 | */ |
| 2544 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2545 | { |
| 2546 | int status, ret = NFS_OK; |
| 2547 | struct nfs4_lock_state *lsp; |
| 2548 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2549 | |
| 2550 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2551 | goto out; |
| 2552 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2553 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2554 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2555 | |
| 2556 | status = nfs41_test_and_free_expired_stateid(server, |
| 2557 | &lsp->ls_stateid, |
| 2558 | cred); |
| 2559 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2560 | if (status == -NFS4ERR_EXPIRED || |
| 2561 | status == -NFS4ERR_BAD_STATEID) { |
| 2562 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame^] | 2563 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2564 | if (!recover_lost_locks) |
| 2565 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2566 | } else if (status != NFS_OK) { |
| 2567 | ret = status; |
| 2568 | break; |
| 2569 | } |
| 2570 | } |
| 2571 | }; |
| 2572 | out: |
| 2573 | return ret; |
| 2574 | } |
| 2575 | |
| 2576 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2577 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2578 | * |
| 2579 | * @state: NFSv4 state for an inode |
| 2580 | * |
| 2581 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2582 | * Otherwise a negative NFS4ERR value is returned. |
| 2583 | */ |
| 2584 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2585 | { |
| 2586 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2587 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2588 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2589 | int status; |
| 2590 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2591 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
| 2592 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 2593 | return NFS_OK; |
| 2594 | return -NFS4ERR_BAD_STATEID; |
| 2595 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2596 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2597 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2598 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2599 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2600 | return -NFS4ERR_BAD_STATEID; |
| 2601 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2602 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2603 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2604 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2605 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2606 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2607 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2608 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame^] | 2609 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2610 | } |
| 2611 | return status; |
| 2612 | } |
| 2613 | |
| 2614 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2615 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2616 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2617 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2618 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2619 | status = nfs41_check_expired_locks(state); |
| 2620 | if (status != NFS_OK) |
| 2621 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2622 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2623 | if (status != NFS_OK) |
| 2624 | status = nfs4_open_expired(sp, state); |
| 2625 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2626 | } |
| 2627 | #endif |
| 2628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2630 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2631 | * fields corresponding to attributes that were used to store the verifier. |
| 2632 | * Make sure we clobber those fields in the later setattr call |
| 2633 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2634 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2635 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2636 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2637 | const u32 *attrset = opendata->o_res.attrset; |
| 2638 | |
| 2639 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2640 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2641 | sattr->ia_valid |= ATTR_ATIME; |
| 2642 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2643 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2644 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2645 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2646 | |
| 2647 | /* Except MODE, it seems harmless of setting twice. */ |
| 2648 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2649 | sattr->ia_valid &= ~ATTR_MODE; |
| 2650 | |
| 2651 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2652 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2655 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2656 | fmode_t fmode, |
| 2657 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2658 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2659 | { |
| 2660 | struct nfs4_state_owner *sp = opendata->owner; |
| 2661 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2662 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2663 | struct nfs4_state *state; |
| 2664 | unsigned int seq; |
| 2665 | int ret; |
| 2666 | |
| 2667 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2668 | |
| 2669 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2670 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2671 | goto out; |
| 2672 | |
| 2673 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2674 | ret = PTR_ERR(state); |
| 2675 | if (IS_ERR(state)) |
| 2676 | goto out; |
| 2677 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2678 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2679 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2680 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2681 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2682 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2683 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2684 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2685 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2686 | alias = d_exact_alias(dentry, state->inode); |
| 2687 | if (!alias) |
| 2688 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2689 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2690 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2691 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2692 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2693 | } |
| 2694 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2695 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2696 | } |
| 2697 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2698 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2699 | if (ret != 0) |
| 2700 | goto out; |
| 2701 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2702 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2703 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2704 | nfs_inode_attach_open_context(ctx); |
| 2705 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2706 | nfs4_schedule_stateid_recovery(server, state); |
| 2707 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2708 | out: |
| 2709 | return ret; |
| 2710 | } |
| 2711 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2712 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2713 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2715 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2716 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2717 | int flags, |
| 2718 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2719 | struct nfs4_label *label, |
| 2720 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | { |
| 2722 | struct nfs4_state_owner *sp; |
| 2723 | struct nfs4_state *state = NULL; |
| 2724 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2725 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2726 | struct dentry *dentry = ctx->dentry; |
| 2727 | struct rpc_cred *cred = ctx->cred; |
| 2728 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2729 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2730 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2731 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2732 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | |
| 2734 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2736 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2737 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2739 | goto out_err; |
| 2740 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2741 | status = nfs4_recover_expired_lease(server); |
| 2742 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2743 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2744 | if (d_really_is_positive(dentry)) |
| 2745 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2746 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2747 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2748 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2749 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2750 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2751 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2752 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2754 | if (label) { |
| 2755 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2756 | if (IS_ERR(olabel)) { |
| 2757 | status = PTR_ERR(olabel); |
| 2758 | goto err_opendata_put; |
| 2759 | } |
| 2760 | } |
| 2761 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2762 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2763 | if (!opendata->f_attr.mdsthreshold) { |
| 2764 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2765 | if (!opendata->f_attr.mdsthreshold) |
| 2766 | goto err_free_label; |
| 2767 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2768 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2769 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2770 | if (d_really_is_positive(dentry)) |
| 2771 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2772 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2773 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2774 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2775 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2776 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2777 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2778 | 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] | 2779 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2780 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2781 | /* |
| 2782 | * send create attributes which was not set by open |
| 2783 | * with an extra setattr. |
| 2784 | */ |
| 2785 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2786 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2787 | status = nfs4_do_setattr(state->inode, cred, |
| 2788 | opendata->o_res.f_attr, sattr, |
| 2789 | state, label, olabel); |
| 2790 | if (status == 0) { |
| 2791 | nfs_setattr_update_inode(state->inode, sattr, |
| 2792 | opendata->o_res.f_attr); |
| 2793 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2794 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2795 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2796 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2797 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2798 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2799 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2800 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2801 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2802 | opendata->f_attr.mdsthreshold = NULL; |
| 2803 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2804 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2805 | nfs4_label_free(olabel); |
| 2806 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2807 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2810 | err_free_label: |
| 2811 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2812 | err_opendata_put: |
| 2813 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2814 | err_put_state_owner: |
| 2815 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | return status; |
| 2818 | } |
| 2819 | |
| 2820 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2821 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2822 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2823 | int flags, |
| 2824 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2825 | struct nfs4_label *label, |
| 2826 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2828 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | struct nfs4_exception exception = { }; |
| 2830 | struct nfs4_state *res; |
| 2831 | int status; |
| 2832 | |
| 2833 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2834 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2835 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2836 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | if (status == 0) |
| 2838 | break; |
| 2839 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2840 | * book-keeping w.r.t. state-changing operations |
| 2841 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2842 | * It is actually a sign of a bug on the client or on the server. |
| 2843 | * |
| 2844 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2845 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | * have unhashed the old state_owner for us, and that we can |
| 2847 | * therefore safely retry using a new one. We should still warn |
| 2848 | * the user though... |
| 2849 | */ |
| 2850 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2851 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2852 | " returned a bad sequence-id error!\n", |
| 2853 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | exception.retry = 1; |
| 2855 | continue; |
| 2856 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2857 | /* |
| 2858 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2859 | * state before it received the OPEN_CONFIRM. |
| 2860 | * Recover by retrying the request as per the discussion |
| 2861 | * on Page 181 of RFC3530. |
| 2862 | */ |
| 2863 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2864 | exception.retry = 1; |
| 2865 | continue; |
| 2866 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2867 | if (status == -EAGAIN) { |
| 2868 | /* We must have found a delegation */ |
| 2869 | exception.retry = 1; |
| 2870 | continue; |
| 2871 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2872 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2873 | continue; |
| 2874 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | status, &exception)); |
| 2876 | } while (exception.retry); |
| 2877 | return res; |
| 2878 | } |
| 2879 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2880 | static int _nfs4_do_setattr(struct inode *inode, |
| 2881 | struct nfs_setattrargs *arg, |
| 2882 | struct nfs_setattrres *res, |
| 2883 | struct rpc_cred *cred, |
| 2884 | struct nfs4_state *state) |
| 2885 | { |
| 2886 | struct nfs_server *server = NFS_SERVER(inode); |
| 2887 | struct rpc_message msg = { |
| 2888 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2889 | .rpc_argp = arg, |
| 2890 | .rpc_resp = res, |
| 2891 | .rpc_cred = cred, |
| 2892 | }; |
| 2893 | struct rpc_cred *delegation_cred = NULL; |
| 2894 | unsigned long timestamp = jiffies; |
| 2895 | fmode_t fmode; |
| 2896 | bool truncate; |
| 2897 | int status; |
| 2898 | |
| 2899 | nfs_fattr_init(res->fattr); |
| 2900 | |
| 2901 | /* Servers should only apply open mode checks for file size changes */ |
| 2902 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2903 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2904 | |
| 2905 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2906 | /* Use that stateid */ |
| 2907 | } else if (truncate && state != NULL) { |
| 2908 | struct nfs_lockowner lockowner = { |
| 2909 | .l_owner = current->files, |
| 2910 | .l_pid = current->tgid, |
| 2911 | }; |
| 2912 | if (!nfs4_valid_open_stateid(state)) |
| 2913 | return -EBADF; |
| 2914 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2915 | &arg->stateid, &delegation_cred) == -EIO) |
| 2916 | return -EBADF; |
| 2917 | } else |
| 2918 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2919 | if (delegation_cred) |
| 2920 | msg.rpc_cred = delegation_cred; |
| 2921 | |
| 2922 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2923 | |
| 2924 | put_rpccred(delegation_cred); |
| 2925 | if (status == 0 && state != NULL) |
| 2926 | renew_lease(server, timestamp); |
| 2927 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2928 | return status; |
| 2929 | } |
| 2930 | |
| 2931 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2932 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2933 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2934 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2936 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2938 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | .iap = sattr, |
| 2940 | .server = server, |
| 2941 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2942 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | }; |
| 2944 | struct nfs_setattrres res = { |
| 2945 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2946 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | .server = server, |
| 2948 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2949 | struct nfs4_exception exception = { |
| 2950 | .state = state, |
| 2951 | .inode = inode, |
| 2952 | .stateid = &arg.stateid, |
| 2953 | }; |
| 2954 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2956 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2957 | if (ilabel) |
| 2958 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2961 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2962 | switch (err) { |
| 2963 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2964 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2965 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2966 | "applying open mode checks to " |
| 2967 | "a SETATTR that is not " |
| 2968 | "changing file size.\n", |
| 2969 | server->nfs_client->cl_hostname); |
| 2970 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2971 | if (state && !(state->state & FMODE_WRITE)) { |
| 2972 | err = -EBADF; |
| 2973 | if (sattr->ia_valid & ATTR_OPEN) |
| 2974 | err = -EACCES; |
| 2975 | goto out; |
| 2976 | } |
| 2977 | } |
| 2978 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2980 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | return err; |
| 2982 | } |
| 2983 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2984 | static bool |
| 2985 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2986 | { |
| 2987 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2988 | return false; |
| 2989 | |
| 2990 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2991 | } |
| 2992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | struct nfs4_closedata { |
| 2994 | struct inode *inode; |
| 2995 | struct nfs4_state *state; |
| 2996 | struct nfs_closeargs arg; |
| 2997 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2998 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2999 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3000 | bool roc; |
| 3001 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | }; |
| 3003 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3004 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3005 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3006 | struct nfs4_closedata *calldata = data; |
| 3007 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3008 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3009 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3010 | if (calldata->roc) |
| 3011 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3012 | nfs4_put_open_state(calldata->state); |
| 3013 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3014 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3015 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3016 | kfree(calldata); |
| 3017 | } |
| 3018 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3019 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3021 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3024 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3026 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3027 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3028 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3029 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | /* hmm. we are done with the inode, and in the process of freeing |
| 3031 | * the state_owner. we keep this around to process errors |
| 3032 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | switch (task->tk_status) { |
| 3034 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3035 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3036 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3037 | pnfs_roc_set_barrier(state->inode, |
| 3038 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3039 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3040 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3041 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3043 | case -NFS4ERR_EXPIRED: |
| 3044 | nfs4_free_revoked_stateid(server, |
| 3045 | &calldata->arg.stateid, |
| 3046 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3047 | case -NFS4ERR_OLD_STATEID: |
| 3048 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3049 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3050 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3051 | rpc_restart_call_prepare(task); |
| 3052 | goto out_release; |
| 3053 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3054 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3055 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3057 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3058 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3059 | goto out_release; |
| 3060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3062 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3063 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3064 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3065 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3066 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3067 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3070 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3072 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3073 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3074 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3075 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3076 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3077 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3078 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3079 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3080 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3081 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3082 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3083 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3084 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3085 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3086 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3087 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3088 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3089 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3090 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3091 | if (state->n_rdonly == 0) |
| 3092 | call_close |= is_rdonly; |
| 3093 | else if (is_rdonly) |
| 3094 | calldata->arg.fmode |= FMODE_READ; |
| 3095 | if (state->n_wronly == 0) |
| 3096 | call_close |= is_wronly; |
| 3097 | else if (is_wronly) |
| 3098 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3099 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3100 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3101 | } else if (is_rdwr) |
| 3102 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3103 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3104 | if (!nfs4_valid_open_stateid(state)) |
| 3105 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3106 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3107 | |
| 3108 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3109 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3110 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3111 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3112 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3113 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 3114 | nfs_release_seqid(calldata->arg.seqid); |
| 3115 | goto out_wait; |
| 3116 | } |
| 3117 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3118 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3119 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3120 | if (calldata->roc) |
| 3121 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 3122 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3123 | calldata->arg.share_access = |
| 3124 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3125 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3126 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3127 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3128 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3129 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3130 | &calldata->arg.seq_args, |
| 3131 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3132 | task) != 0) |
| 3133 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3134 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3135 | return; |
| 3136 | out_no_action: |
| 3137 | task->tk_action = NULL; |
| 3138 | out_wait: |
| 3139 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3142 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3143 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3144 | .rpc_call_done = nfs4_close_done, |
| 3145 | .rpc_release = nfs4_free_closedata, |
| 3146 | }; |
| 3147 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3148 | static bool nfs4_roc(struct inode *inode) |
| 3149 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3150 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3151 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3152 | return pnfs_roc(inode); |
| 3153 | } |
| 3154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | /* |
| 3156 | * It is possible for data to be read/written from a mem-mapped file |
| 3157 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3158 | * This means that we can't safely call nfsv4 close on a file until |
| 3159 | * the inode is cleared. This in turn means that we are not good |
| 3160 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3161 | * share state even when we are done with one of the three share |
| 3162 | * stateid's in the inode. |
| 3163 | * |
| 3164 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3165 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3166 | 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] | 3167 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3168 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3169 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3171 | struct nfs4_state_owner *sp = state->owner; |
| 3172 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3173 | struct rpc_message msg = { |
| 3174 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3175 | .rpc_cred = state->owner->so_cred, |
| 3176 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3177 | struct rpc_task_setup task_setup_data = { |
| 3178 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3179 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3180 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3181 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3182 | .flags = RPC_TASK_ASYNC, |
| 3183 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3184 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3186 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3187 | &task_setup_data.rpc_client, &msg); |
| 3188 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3189 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3191 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3192 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3193 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3195 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3197 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3198 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3199 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3200 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3201 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3202 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3203 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3204 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3205 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3206 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3207 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3208 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3209 | msg.rpc_argp = &calldata->arg; |
| 3210 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3211 | task_setup_data.callback_data = calldata; |
| 3212 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3213 | if (IS_ERR(task)) |
| 3214 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3215 | status = 0; |
| 3216 | if (wait) |
| 3217 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3218 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3219 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3220 | out_free_calldata: |
| 3221 | kfree(calldata); |
| 3222 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3223 | nfs4_put_open_state(state); |
| 3224 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3225 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3228 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3229 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3230 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3233 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3234 | |
| 3235 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3237 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3238 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3239 | |
| 3240 | nfs4_label_release_security(label); |
| 3241 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3242 | if (IS_ERR(state)) |
| 3243 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3244 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3247 | 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] | 3248 | { |
| 3249 | if (ctx->state == NULL) |
| 3250 | return; |
| 3251 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3252 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3253 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3254 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3257 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3258 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3259 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3262 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3263 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3264 | struct nfs4_server_caps_arg args = { |
| 3265 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3266 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3267 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | struct nfs4_server_caps_res res = {}; |
| 3269 | struct rpc_message msg = { |
| 3270 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3271 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | .rpc_resp = &res, |
| 3273 | }; |
| 3274 | int status; |
| 3275 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3276 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3277 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3278 | FATTR4_WORD0_LINK_SUPPORT | |
| 3279 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3280 | FATTR4_WORD0_ACLSUPPORT; |
| 3281 | if (minorversion) |
| 3282 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3283 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3284 | 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] | 3285 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3286 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3287 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3288 | case 0: |
| 3289 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3290 | res.attr_bitmask[2] = 0; |
| 3291 | break; |
| 3292 | case 1: |
| 3293 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3294 | break; |
| 3295 | case 2: |
| 3296 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3299 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3300 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3301 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3302 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3303 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3304 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3305 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3306 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | server->caps |= NFS_CAP_ACLS; |
| 3308 | if (res.has_links != 0) |
| 3309 | server->caps |= NFS_CAP_HARDLINKS; |
| 3310 | if (res.has_symlinks != 0) |
| 3311 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3312 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3313 | server->caps |= NFS_CAP_FILEID; |
| 3314 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3315 | server->caps |= NFS_CAP_MODE; |
| 3316 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3317 | server->caps |= NFS_CAP_NLINK; |
| 3318 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3319 | server->caps |= NFS_CAP_OWNER; |
| 3320 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3321 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3322 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3323 | server->caps |= NFS_CAP_ATIME; |
| 3324 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3325 | server->caps |= NFS_CAP_CTIME; |
| 3326 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3327 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3328 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3329 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3330 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3331 | #endif |
| 3332 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3333 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3334 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3335 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3336 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3337 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3338 | 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] | 3339 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3340 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3341 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3343 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | return status; |
| 3347 | } |
| 3348 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3349 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
| 3351 | struct nfs4_exception exception = { }; |
| 3352 | int err; |
| 3353 | do { |
| 3354 | err = nfs4_handle_exception(server, |
| 3355 | _nfs4_server_capabilities(server, fhandle), |
| 3356 | &exception); |
| 3357 | } while (exception.retry); |
| 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3362 | struct nfs_fsinfo *info) |
| 3363 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3364 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3366 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | }; |
| 3368 | struct nfs4_lookup_res res = { |
| 3369 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3370 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | .fh = fhandle, |
| 3372 | }; |
| 3373 | struct rpc_message msg = { |
| 3374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3375 | .rpc_argp = &args, |
| 3376 | .rpc_resp = &res, |
| 3377 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3378 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3379 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3380 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3381 | /* |
| 3382 | * Process the label in the upcoming getfattr |
| 3383 | */ |
| 3384 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3385 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3386 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3387 | 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] | 3388 | } |
| 3389 | |
| 3390 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3391 | struct nfs_fsinfo *info) |
| 3392 | { |
| 3393 | struct nfs4_exception exception = { }; |
| 3394 | int err; |
| 3395 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3396 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3397 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3398 | switch (err) { |
| 3399 | case 0: |
| 3400 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3401 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3402 | default: |
| 3403 | err = nfs4_handle_exception(server, err, &exception); |
| 3404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3406 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | return err; |
| 3408 | } |
| 3409 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3410 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3411 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3412 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3413 | struct rpc_auth_create_args auth_args = { |
| 3414 | .pseudoflavor = flavor, |
| 3415 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3416 | struct rpc_auth *auth; |
| 3417 | int ret; |
| 3418 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3419 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3420 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3421 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3422 | goto out; |
| 3423 | } |
| 3424 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3425 | out: |
| 3426 | return ret; |
| 3427 | } |
| 3428 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3429 | /* |
| 3430 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3431 | * |
| 3432 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3433 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3434 | * |
| 3435 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3436 | * negative errno value. |
| 3437 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3438 | 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] | 3439 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3441 | /* Per 3530bis 15.33.5 */ |
| 3442 | static const rpc_authflavor_t flav_array[] = { |
| 3443 | RPC_AUTH_GSS_KRB5P, |
| 3444 | RPC_AUTH_GSS_KRB5I, |
| 3445 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3446 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3447 | RPC_AUTH_NULL, |
| 3448 | }; |
| 3449 | int status = -EPERM; |
| 3450 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3452 | if (server->auth_info.flavor_len > 0) { |
| 3453 | /* try each flavor specified by user */ |
| 3454 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3455 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3456 | server->auth_info.flavors[i]); |
| 3457 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3458 | continue; |
| 3459 | break; |
| 3460 | } |
| 3461 | } else { |
| 3462 | /* no flavors specified by user, try default list */ |
| 3463 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3464 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3465 | flav_array[i]); |
| 3466 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3467 | continue; |
| 3468 | break; |
| 3469 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3470 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3471 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3472 | /* |
| 3473 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3474 | * to access the mount. It could also mean that we tried to mount |
| 3475 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3476 | * existing mount programs don't handle -EACCES very well so it should |
| 3477 | * be mapped to -EPERM instead. |
| 3478 | */ |
| 3479 | if (status == -EACCES) |
| 3480 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3481 | return status; |
| 3482 | } |
| 3483 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3484 | /** |
| 3485 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3486 | * @server: initialized nfs_server handle |
| 3487 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3488 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3489 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3490 | * |
| 3491 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3492 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3493 | 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] | 3494 | struct nfs_fsinfo *info, |
| 3495 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3496 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3497 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3498 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3499 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3500 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3501 | |
| 3502 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3503 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3504 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | if (status == 0) |
| 3507 | status = nfs4_server_capabilities(server, fhandle); |
| 3508 | if (status == 0) |
| 3509 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3510 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3511 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3514 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3515 | struct nfs_fsinfo *info) |
| 3516 | { |
| 3517 | int error; |
| 3518 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3519 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3520 | |
| 3521 | error = nfs4_server_capabilities(server, mntfh); |
| 3522 | if (error < 0) { |
| 3523 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3524 | return error; |
| 3525 | } |
| 3526 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3527 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3528 | if (IS_ERR(label)) |
| 3529 | return PTR_ERR(label); |
| 3530 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3531 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3532 | if (error < 0) { |
| 3533 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3534 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3538 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3539 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3540 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3541 | err_free_label: |
| 3542 | nfs4_label_free(label); |
| 3543 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3544 | return error; |
| 3545 | } |
| 3546 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3547 | /* |
| 3548 | * Get locations and (maybe) other attributes of a referral. |
| 3549 | * Note that we'll actually follow the referral later when |
| 3550 | * we detect fsid mismatch in inode revalidation |
| 3551 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3552 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3553 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3554 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3555 | { |
| 3556 | int status = -ENOMEM; |
| 3557 | struct page *page = NULL; |
| 3558 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3559 | |
| 3560 | page = alloc_page(GFP_KERNEL); |
| 3561 | if (page == NULL) |
| 3562 | goto out; |
| 3563 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3564 | if (locations == NULL) |
| 3565 | goto out; |
| 3566 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3567 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3568 | if (status != 0) |
| 3569 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3570 | |
| 3571 | /* |
| 3572 | * If the fsid didn't change, this is a migration event, not a |
| 3573 | * referral. Cause us to drop into the exception handler, which |
| 3574 | * will kick off migration recovery. |
| 3575 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3576 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3577 | dprintk("%s: server did not return a different fsid for" |
| 3578 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3579 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3580 | goto out; |
| 3581 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3582 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3583 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3584 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3585 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3586 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3587 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3588 | out: |
| 3589 | if (page) |
| 3590 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3591 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3592 | return status; |
| 3593 | } |
| 3594 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3595 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3596 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | { |
| 3598 | struct nfs4_getattr_arg args = { |
| 3599 | .fh = fhandle, |
| 3600 | .bitmask = server->attr_bitmask, |
| 3601 | }; |
| 3602 | struct nfs4_getattr_res res = { |
| 3603 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3604 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | .server = server, |
| 3606 | }; |
| 3607 | struct rpc_message msg = { |
| 3608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3609 | .rpc_argp = &args, |
| 3610 | .rpc_resp = &res, |
| 3611 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3612 | |
| 3613 | args.bitmask = nfs4_bitmask(server, label); |
| 3614 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3615 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3616 | 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] | 3617 | } |
| 3618 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3619 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3620 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | { |
| 3622 | struct nfs4_exception exception = { }; |
| 3623 | int err; |
| 3624 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3625 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3626 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3627 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | &exception); |
| 3629 | } while (exception.retry); |
| 3630 | return err; |
| 3631 | } |
| 3632 | |
| 3633 | /* |
| 3634 | * The file is not closed if it is opened due to the a request to change |
| 3635 | * the size of the file. The open call will not be needed once the |
| 3636 | * VFS layer lookup-intents are implemented. |
| 3637 | * |
| 3638 | * Close is called when the inode is destroyed. |
| 3639 | * If we haven't opened the file for O_WRONLY, we |
| 3640 | * need to in the size_change case to obtain a stateid. |
| 3641 | * |
| 3642 | * Got race? |
| 3643 | * Because OPEN is always done by name in nfsv4, it is |
| 3644 | * possible that we opened a different file by the same |
| 3645 | * name. We can recognize this race condition, but we |
| 3646 | * can't do anything about it besides returning an error. |
| 3647 | * |
| 3648 | * This will be fixed with VFS changes (lookup-intent). |
| 3649 | */ |
| 3650 | static int |
| 3651 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3652 | struct iattr *sattr) |
| 3653 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3654 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3655 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3656 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3657 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | int status; |
| 3659 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3660 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3661 | sattr->ia_valid & ATTR_SIZE && |
| 3662 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3663 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3664 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3665 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3667 | /* Deal with open(O_TRUNC) */ |
| 3668 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3669 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3670 | |
| 3671 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3672 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3673 | return 0; |
| 3674 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3675 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3676 | if (sattr->ia_valid & ATTR_FILE) { |
| 3677 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3678 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3679 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3680 | if (ctx) { |
| 3681 | cred = ctx->cred; |
| 3682 | state = ctx->state; |
| 3683 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3686 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3687 | if (IS_ERR(label)) |
| 3688 | return PTR_ERR(label); |
| 3689 | |
| 3690 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3691 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3692 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3693 | nfs_setsecurity(inode, fattr, label); |
| 3694 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3695 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return status; |
| 3697 | } |
| 3698 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3699 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3700 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3701 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3702 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3703 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3704 | int status; |
| 3705 | struct nfs4_lookup_arg args = { |
| 3706 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3707 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3708 | .name = name, |
| 3709 | }; |
| 3710 | struct nfs4_lookup_res res = { |
| 3711 | .server = server, |
| 3712 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3713 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3714 | .fh = fhandle, |
| 3715 | }; |
| 3716 | struct rpc_message msg = { |
| 3717 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3718 | .rpc_argp = &args, |
| 3719 | .rpc_resp = &res, |
| 3720 | }; |
| 3721 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3722 | args.bitmask = nfs4_bitmask(server, label); |
| 3723 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3724 | nfs_fattr_init(fattr); |
| 3725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3727 | 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] | 3728 | dprintk("NFS reply lookup: %d\n", status); |
| 3729 | return status; |
| 3730 | } |
| 3731 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3732 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3733 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3734 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3735 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3736 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3737 | fattr->nlink = 2; |
| 3738 | } |
| 3739 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3740 | 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] | 3741 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3742 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3743 | { |
| 3744 | struct nfs4_exception exception = { }; |
| 3745 | struct rpc_clnt *client = *clnt; |
| 3746 | int err; |
| 3747 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3748 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3749 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3750 | switch (err) { |
| 3751 | case -NFS4ERR_BADNAME: |
| 3752 | err = -ENOENT; |
| 3753 | goto out; |
| 3754 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3755 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3756 | if (err == -NFS4ERR_MOVED) |
| 3757 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3758 | goto out; |
| 3759 | case -NFS4ERR_WRONGSEC: |
| 3760 | err = -EPERM; |
| 3761 | if (client != *clnt) |
| 3762 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3763 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3764 | if (IS_ERR(client)) |
| 3765 | return PTR_ERR(client); |
| 3766 | |
| 3767 | exception.retry = 1; |
| 3768 | break; |
| 3769 | default: |
| 3770 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3771 | } |
| 3772 | } while (exception.retry); |
| 3773 | |
| 3774 | out: |
| 3775 | if (err == 0) |
| 3776 | *clnt = client; |
| 3777 | else if (client != *clnt) |
| 3778 | rpc_shutdown_client(client); |
| 3779 | |
| 3780 | return err; |
| 3781 | } |
| 3782 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3783 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3784 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3785 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3787 | int status; |
| 3788 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3789 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3790 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3791 | if (client != NFS_CLIENT(dir)) { |
| 3792 | rpc_shutdown_client(client); |
| 3793 | nfs_fixup_secinfo_attributes(fattr); |
| 3794 | } |
| 3795 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3798 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3799 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3800 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3801 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3802 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3803 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3804 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3805 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3806 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3807 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3808 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3809 | } |
| 3810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3812 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3813 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | struct nfs4_accessargs args = { |
| 3815 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3816 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3818 | struct nfs4_accessres res = { |
| 3819 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3820 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | struct rpc_message msg = { |
| 3822 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3823 | .rpc_argp = &args, |
| 3824 | .rpc_resp = &res, |
| 3825 | .rpc_cred = entry->cred, |
| 3826 | }; |
| 3827 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3828 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | |
| 3830 | /* |
| 3831 | * Determine which access bits we want to ask for... |
| 3832 | */ |
| 3833 | if (mode & MAY_READ) |
| 3834 | args.access |= NFS4_ACCESS_READ; |
| 3835 | if (S_ISDIR(inode->i_mode)) { |
| 3836 | if (mode & MAY_WRITE) |
| 3837 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3838 | if (mode & MAY_EXEC) |
| 3839 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3840 | } else { |
| 3841 | if (mode & MAY_WRITE) |
| 3842 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3843 | if (mode & MAY_EXEC) |
| 3844 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3845 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3846 | |
| 3847 | res.fattr = nfs_alloc_fattr(); |
| 3848 | if (res.fattr == NULL) |
| 3849 | return -ENOMEM; |
| 3850 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3851 | 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] | 3852 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3853 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3854 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3856 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | return status; |
| 3858 | } |
| 3859 | |
| 3860 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3861 | { |
| 3862 | struct nfs4_exception exception = { }; |
| 3863 | int err; |
| 3864 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3865 | err = _nfs4_proc_access(inode, entry); |
| 3866 | trace_nfs4_access(inode, err); |
| 3867 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | &exception); |
| 3869 | } while (exception.retry); |
| 3870 | return err; |
| 3871 | } |
| 3872 | |
| 3873 | /* |
| 3874 | * TODO: For the time being, we don't try to get any attributes |
| 3875 | * along with any of the zero-copy operations READ, READDIR, |
| 3876 | * READLINK, WRITE. |
| 3877 | * |
| 3878 | * In the case of the first three, we want to put the GETATTR |
| 3879 | * after the read-type operation -- this is because it is hard |
| 3880 | * to predict the length of a GETATTR response in v4, and thus |
| 3881 | * align the READ data correctly. This means that the GETATTR |
| 3882 | * may end up partially falling into the page cache, and we should |
| 3883 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3884 | * To do this efficiently, we need to know the total length |
| 3885 | * of data received, which doesn't seem to be available outside |
| 3886 | * of the RPC layer. |
| 3887 | * |
| 3888 | * In the case of WRITE, we also want to put the GETATTR after |
| 3889 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3890 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | * |
| 3892 | * Both of these changes to the XDR layer would in fact be quite |
| 3893 | * minor, but I decided to leave them for a subsequent patch. |
| 3894 | */ |
| 3895 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3896 | unsigned int pgbase, unsigned int pglen) |
| 3897 | { |
| 3898 | struct nfs4_readlink args = { |
| 3899 | .fh = NFS_FH(inode), |
| 3900 | .pgbase = pgbase, |
| 3901 | .pglen = pglen, |
| 3902 | .pages = &page, |
| 3903 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3904 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | struct rpc_message msg = { |
| 3906 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3907 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3908 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | }; |
| 3910 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3911 | 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] | 3912 | } |
| 3913 | |
| 3914 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3915 | unsigned int pgbase, unsigned int pglen) |
| 3916 | { |
| 3917 | struct nfs4_exception exception = { }; |
| 3918 | int err; |
| 3919 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3920 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3921 | trace_nfs4_readlink(inode, err); |
| 3922 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | &exception); |
| 3924 | } while (exception.retry); |
| 3925 | return err; |
| 3926 | } |
| 3927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3929 | * 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] | 3930 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | static int |
| 3932 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3933 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3935 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3936 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | int status = 0; |
| 3939 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3940 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3941 | if (IS_ERR(ctx)) |
| 3942 | return PTR_ERR(ctx); |
| 3943 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3944 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3945 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3946 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3947 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | if (IS_ERR(state)) { |
| 3949 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3950 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3953 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3954 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | return status; |
| 3956 | } |
| 3957 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3958 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3960 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3961 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3963 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3965 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3966 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3967 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3969 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3970 | .rpc_argp = &args, |
| 3971 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3973 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3974 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3975 | 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] | 3976 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3977 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | return status; |
| 3979 | } |
| 3980 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3981 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | { |
| 3983 | struct nfs4_exception exception = { }; |
| 3984 | int err; |
| 3985 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3986 | err = _nfs4_proc_remove(dir, name); |
| 3987 | trace_nfs4_remove(dir, name, err); |
| 3988 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | &exception); |
| 3990 | } while (exception.retry); |
| 3991 | return err; |
| 3992 | } |
| 3993 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3994 | 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] | 3995 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3996 | struct nfs_server *server = NFS_SERVER(dir); |
| 3997 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3998 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4000 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4002 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4003 | |
| 4004 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4007 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4008 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4009 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4010 | &data->args.seq_args, |
| 4011 | &data->res.seq_res, |
| 4012 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4015 | 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] | 4016 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4017 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4018 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4019 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4020 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4021 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4022 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4023 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4024 | return 0; |
| 4025 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4026 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4029 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4030 | { |
| 4031 | struct nfs_server *server = NFS_SERVER(dir); |
| 4032 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4033 | struct nfs_renameres *res = msg->rpc_resp; |
| 4034 | |
| 4035 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4036 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4037 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4038 | } |
| 4039 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4040 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4041 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4042 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4043 | &data->args.seq_args, |
| 4044 | &data->res.seq_res, |
| 4045 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4049 | struct inode *new_dir) |
| 4050 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4051 | struct nfs_renamedata *data = task->tk_calldata; |
| 4052 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4053 | |
| 4054 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4055 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4056 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4057 | return 0; |
| 4058 | |
| 4059 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4060 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4061 | return 1; |
| 4062 | } |
| 4063 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4064 | 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] | 4065 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4066 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | struct nfs4_link_arg arg = { |
| 4068 | .fh = NFS_FH(inode), |
| 4069 | .dir_fh = NFS_FH(dir), |
| 4070 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4071 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4073 | struct nfs4_link_res res = { |
| 4074 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4075 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4076 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | struct rpc_message msg = { |
| 4078 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4079 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4080 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4082 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4084 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4085 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4086 | goto out; |
| 4087 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4088 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4089 | if (IS_ERR(res.label)) { |
| 4090 | status = PTR_ERR(res.label); |
| 4091 | goto out; |
| 4092 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4093 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4094 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4095 | 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] | 4096 | if (!status) { |
| 4097 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4098 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4099 | if (!status) |
| 4100 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4101 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4102 | |
| 4103 | |
| 4104 | nfs4_label_free(res.label); |
| 4105 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4106 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4107 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | return status; |
| 4109 | } |
| 4110 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4111 | 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] | 4112 | { |
| 4113 | struct nfs4_exception exception = { }; |
| 4114 | int err; |
| 4115 | do { |
| 4116 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4117 | _nfs4_proc_link(inode, dir, name), |
| 4118 | &exception); |
| 4119 | } while (exception.retry); |
| 4120 | return err; |
| 4121 | } |
| 4122 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4123 | struct nfs4_createdata { |
| 4124 | struct rpc_message msg; |
| 4125 | struct nfs4_create_arg arg; |
| 4126 | struct nfs4_create_res res; |
| 4127 | struct nfs_fh fh; |
| 4128 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4129 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4130 | }; |
| 4131 | |
| 4132 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4133 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4134 | { |
| 4135 | struct nfs4_createdata *data; |
| 4136 | |
| 4137 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4138 | if (data != NULL) { |
| 4139 | struct nfs_server *server = NFS_SERVER(dir); |
| 4140 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4141 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4142 | if (IS_ERR(data->label)) |
| 4143 | goto out_free; |
| 4144 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4145 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4146 | data->msg.rpc_argp = &data->arg; |
| 4147 | data->msg.rpc_resp = &data->res; |
| 4148 | data->arg.dir_fh = NFS_FH(dir); |
| 4149 | data->arg.server = server; |
| 4150 | data->arg.name = name; |
| 4151 | data->arg.attrs = sattr; |
| 4152 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4153 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4154 | data->res.server = server; |
| 4155 | data->res.fh = &data->fh; |
| 4156 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4157 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4158 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4159 | } |
| 4160 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4161 | out_free: |
| 4162 | kfree(data); |
| 4163 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4167 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4168 | 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] | 4169 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4170 | if (status == 0) { |
| 4171 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4172 | 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] | 4173 | } |
| 4174 | return status; |
| 4175 | } |
| 4176 | |
| 4177 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4178 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4179 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4180 | kfree(data); |
| 4181 | } |
| 4182 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4183 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4184 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4185 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4187 | struct nfs4_createdata *data; |
| 4188 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4190 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4191 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4192 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4193 | status = -ENOMEM; |
| 4194 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4195 | if (data == NULL) |
| 4196 | goto out; |
| 4197 | |
| 4198 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4199 | data->arg.u.symlink.pages = &page; |
| 4200 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4201 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4203 | status = nfs4_do_create(dir, dentry, data); |
| 4204 | |
| 4205 | nfs4_free_createdata(data); |
| 4206 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | return status; |
| 4208 | } |
| 4209 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4210 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4211 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | { |
| 4213 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4214 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4216 | |
| 4217 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4220 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4221 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4222 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | &exception); |
| 4224 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4225 | |
| 4226 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | return err; |
| 4228 | } |
| 4229 | |
| 4230 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4231 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4233 | struct nfs4_createdata *data; |
| 4234 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4236 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4237 | if (data == NULL) |
| 4238 | goto out; |
| 4239 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4240 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4241 | status = nfs4_do_create(dir, dentry, data); |
| 4242 | |
| 4243 | nfs4_free_createdata(data); |
| 4244 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | return status; |
| 4246 | } |
| 4247 | |
| 4248 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4249 | struct iattr *sattr) |
| 4250 | { |
| 4251 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4252 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4254 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4255 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4256 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4257 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4259 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4260 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4261 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | &exception); |
| 4263 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4264 | nfs4_label_release_security(label); |
| 4265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | return err; |
| 4267 | } |
| 4268 | |
| 4269 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4270 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4272 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | struct nfs4_readdir_arg args = { |
| 4274 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4275 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | .pgbase = 0, |
| 4277 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4278 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4279 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | }; |
| 4281 | struct nfs4_readdir_res res; |
| 4282 | struct rpc_message msg = { |
| 4283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4284 | .rpc_argp = &args, |
| 4285 | .rpc_resp = &res, |
| 4286 | .rpc_cred = cred, |
| 4287 | }; |
| 4288 | int status; |
| 4289 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4290 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4291 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4292 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4293 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4295 | 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] | 4296 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4297 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4298 | status += args.pgbase; |
| 4299 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4300 | |
| 4301 | nfs_invalidate_atime(dir); |
| 4302 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4303 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | return status; |
| 4305 | } |
| 4306 | |
| 4307 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4308 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | { |
| 4310 | struct nfs4_exception exception = { }; |
| 4311 | int err; |
| 4312 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4313 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4314 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4315 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4316 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | &exception); |
| 4318 | } while (exception.retry); |
| 4319 | return err; |
| 4320 | } |
| 4321 | |
| 4322 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4323 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4325 | struct nfs4_createdata *data; |
| 4326 | int mode = sattr->ia_mode; |
| 4327 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4329 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4330 | if (data == NULL) |
| 4331 | goto out; |
| 4332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4334 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4336 | data->arg.ftype = NF4BLK; |
| 4337 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4338 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | } |
| 4340 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4341 | data->arg.ftype = NF4CHR; |
| 4342 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4343 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4344 | } else if (!S_ISSOCK(mode)) { |
| 4345 | status = -EINVAL; |
| 4346 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4348 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4349 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4350 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4351 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4352 | nfs4_free_createdata(data); |
| 4353 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | return status; |
| 4355 | } |
| 4356 | |
| 4357 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4358 | struct iattr *sattr, dev_t rdev) |
| 4359 | { |
| 4360 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4361 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4363 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4364 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4365 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4366 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4368 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4369 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4370 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | &exception); |
| 4372 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4373 | |
| 4374 | nfs4_label_release_security(label); |
| 4375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | return err; |
| 4377 | } |
| 4378 | |
| 4379 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4380 | struct nfs_fsstat *fsstat) |
| 4381 | { |
| 4382 | struct nfs4_statfs_arg args = { |
| 4383 | .fh = fhandle, |
| 4384 | .bitmask = server->attr_bitmask, |
| 4385 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4386 | struct nfs4_statfs_res res = { |
| 4387 | .fsstat = fsstat, |
| 4388 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | struct rpc_message msg = { |
| 4390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4391 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4392 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | }; |
| 4394 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4395 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4396 | 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] | 4397 | } |
| 4398 | |
| 4399 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4400 | { |
| 4401 | struct nfs4_exception exception = { }; |
| 4402 | int err; |
| 4403 | do { |
| 4404 | err = nfs4_handle_exception(server, |
| 4405 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4406 | &exception); |
| 4407 | } while (exception.retry); |
| 4408 | return err; |
| 4409 | } |
| 4410 | |
| 4411 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4412 | struct nfs_fsinfo *fsinfo) |
| 4413 | { |
| 4414 | struct nfs4_fsinfo_arg args = { |
| 4415 | .fh = fhandle, |
| 4416 | .bitmask = server->attr_bitmask, |
| 4417 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4418 | struct nfs4_fsinfo_res res = { |
| 4419 | .fsinfo = fsinfo, |
| 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_FSINFO], |
| 4423 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | }; |
| 4426 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4427 | 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] | 4428 | } |
| 4429 | |
| 4430 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4431 | { |
| 4432 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4433 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | int err; |
| 4435 | |
| 4436 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4437 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4438 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4439 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4440 | nfs4_set_lease_period(server->nfs_client, |
| 4441 | fsinfo->lease_time * HZ, |
| 4442 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4443 | break; |
| 4444 | } |
| 4445 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | } while (exception.retry); |
| 4447 | return err; |
| 4448 | } |
| 4449 | |
| 4450 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4451 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4452 | int error; |
| 4453 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4454 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4455 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4456 | if (error == 0) { |
| 4457 | /* block layout checks this! */ |
| 4458 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4459 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4460 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4461 | |
| 4462 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4466 | struct nfs_pathconf *pathconf) |
| 4467 | { |
| 4468 | struct nfs4_pathconf_arg args = { |
| 4469 | .fh = fhandle, |
| 4470 | .bitmask = server->attr_bitmask, |
| 4471 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4472 | struct nfs4_pathconf_res res = { |
| 4473 | .pathconf = pathconf, |
| 4474 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | struct rpc_message msg = { |
| 4476 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4477 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4478 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | }; |
| 4480 | |
| 4481 | /* None of the pathconf attributes are mandatory to implement */ |
| 4482 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4483 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4484 | return 0; |
| 4485 | } |
| 4486 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4487 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4488 | 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] | 4489 | } |
| 4490 | |
| 4491 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4492 | struct nfs_pathconf *pathconf) |
| 4493 | { |
| 4494 | struct nfs4_exception exception = { }; |
| 4495 | int err; |
| 4496 | |
| 4497 | do { |
| 4498 | err = nfs4_handle_exception(server, |
| 4499 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4500 | &exception); |
| 4501 | } while (exception.retry); |
| 4502 | return err; |
| 4503 | } |
| 4504 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4505 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4506 | const struct nfs_open_context *ctx, |
| 4507 | const struct nfs_lock_context *l_ctx, |
| 4508 | fmode_t fmode) |
| 4509 | { |
| 4510 | const struct nfs_lockowner *lockowner = NULL; |
| 4511 | |
| 4512 | if (l_ctx != NULL) |
| 4513 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4514 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4515 | } |
| 4516 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4517 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4518 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4519 | const struct nfs_open_context *ctx, |
| 4520 | const struct nfs_lock_context *l_ctx, |
| 4521 | fmode_t fmode) |
| 4522 | { |
| 4523 | nfs4_stateid current_stateid; |
| 4524 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4525 | /* If the current stateid represents a lost lock, then exit */ |
| 4526 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4527 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4528 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4529 | } |
| 4530 | |
| 4531 | static bool nfs4_error_stateid_expired(int err) |
| 4532 | { |
| 4533 | switch (err) { |
| 4534 | case -NFS4ERR_DELEG_REVOKED: |
| 4535 | case -NFS4ERR_ADMIN_REVOKED: |
| 4536 | case -NFS4ERR_BAD_STATEID: |
| 4537 | case -NFS4ERR_STALE_STATEID: |
| 4538 | case -NFS4ERR_OLD_STATEID: |
| 4539 | case -NFS4ERR_OPENMODE: |
| 4540 | case -NFS4ERR_EXPIRED: |
| 4541 | return true; |
| 4542 | } |
| 4543 | return false; |
| 4544 | } |
| 4545 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4546 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4547 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4548 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4549 | } |
| 4550 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4551 | 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] | 4552 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4553 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4555 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4556 | if (task->tk_status < 0) { |
| 4557 | struct nfs4_exception exception = { |
| 4558 | .inode = hdr->inode, |
| 4559 | .state = hdr->args.context->state, |
| 4560 | .stateid = &hdr->args.stateid, |
| 4561 | }; |
| 4562 | task->tk_status = nfs4_async_handle_exception(task, |
| 4563 | server, task->tk_status, &exception); |
| 4564 | if (exception.retry) { |
| 4565 | rpc_restart_call_prepare(task); |
| 4566 | return -EAGAIN; |
| 4567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4569 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4570 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4572 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4573 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4576 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4577 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4578 | { |
| 4579 | |
| 4580 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4581 | nfs4_stateid_is_current(&args->stateid, |
| 4582 | args->context, |
| 4583 | args->lock_context, |
| 4584 | FMODE_READ)) |
| 4585 | return false; |
| 4586 | rpc_restart_call_prepare(task); |
| 4587 | return true; |
| 4588 | } |
| 4589 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4590 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4591 | { |
| 4592 | |
| 4593 | dprintk("--> %s\n", __func__); |
| 4594 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4595 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4596 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4597 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4598 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4599 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4600 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4603 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4604 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4606 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4607 | if (!hdr->pgio_done_cb) |
| 4608 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4609 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4610 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4613 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4614 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4615 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4616 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4617 | &hdr->args.seq_args, |
| 4618 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4619 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4620 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4621 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4622 | hdr->args.lock_context, |
| 4623 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4624 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4625 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4626 | return -EIO; |
| 4627 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4630 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4631 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4633 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4634 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4635 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4636 | if (task->tk_status < 0) { |
| 4637 | struct nfs4_exception exception = { |
| 4638 | .inode = hdr->inode, |
| 4639 | .state = hdr->args.context->state, |
| 4640 | .stateid = &hdr->args.stateid, |
| 4641 | }; |
| 4642 | task->tk_status = nfs4_async_handle_exception(task, |
| 4643 | NFS_SERVER(inode), task->tk_status, |
| 4644 | &exception); |
| 4645 | if (exception.retry) { |
| 4646 | rpc_restart_call_prepare(task); |
| 4647 | return -EAGAIN; |
| 4648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4650 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4651 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4652 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4653 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4654 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4657 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4658 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4659 | { |
| 4660 | |
| 4661 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4662 | nfs4_stateid_is_current(&args->stateid, |
| 4663 | args->context, |
| 4664 | args->lock_context, |
| 4665 | FMODE_WRITE)) |
| 4666 | return false; |
| 4667 | rpc_restart_call_prepare(task); |
| 4668 | return true; |
| 4669 | } |
| 4670 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | 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] | 4672 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4673 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4674 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4676 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4677 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4678 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4681 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4682 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4683 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4684 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4685 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4686 | return false; |
| 4687 | /* Otherwise, request attributes if and only if we don't hold |
| 4688 | * a delegation |
| 4689 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4690 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4691 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4692 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4693 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4694 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4696 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4697 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4698 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4699 | hdr->args.bitmask = NULL; |
| 4700 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4701 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4703 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4704 | if (!hdr->pgio_done_cb) |
| 4705 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4706 | hdr->res.server = server; |
| 4707 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4709 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4713 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4714 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4715 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4716 | &data->args.seq_args, |
| 4717 | &data->res.seq_res, |
| 4718 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4721 | 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] | 4722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4724 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4725 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4726 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4727 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4728 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4729 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4731 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4734 | 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] | 4735 | { |
| 4736 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4737 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4738 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4741 | 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] | 4742 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4743 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4744 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4745 | if (data->commit_done_cb == NULL) |
| 4746 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4747 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4748 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4749 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4752 | struct nfs4_renewdata { |
| 4753 | struct nfs_client *client; |
| 4754 | unsigned long timestamp; |
| 4755 | }; |
| 4756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | /* |
| 4758 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4759 | * standalone procedure for queueing an asynchronous RENEW. |
| 4760 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4761 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4762 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4763 | struct nfs4_renewdata *data = calldata; |
| 4764 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4765 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4766 | if (atomic_read(&clp->cl_count) > 1) |
| 4767 | nfs4_schedule_state_renewal(clp); |
| 4768 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4769 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4772 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4774 | struct nfs4_renewdata *data = calldata; |
| 4775 | struct nfs_client *clp = data->client; |
| 4776 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4778 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4779 | switch (task->tk_status) { |
| 4780 | case 0: |
| 4781 | break; |
| 4782 | case -NFS4ERR_LEASE_MOVED: |
| 4783 | nfs4_schedule_lease_moved_recovery(clp); |
| 4784 | break; |
| 4785 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4786 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4787 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4788 | return; |
| 4789 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4790 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4791 | return; |
| 4792 | } |
| 4793 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4795 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4798 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4799 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4800 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4801 | }; |
| 4802 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4803 | 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] | 4804 | { |
| 4805 | struct rpc_message msg = { |
| 4806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4807 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4808 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4810 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4812 | if (renew_flags == 0) |
| 4813 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4814 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4815 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4816 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4817 | if (data == NULL) |
| 4818 | return -ENOMEM; |
| 4819 | data->client = clp; |
| 4820 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4821 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4822 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4825 | 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] | 4826 | { |
| 4827 | struct rpc_message msg = { |
| 4828 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4829 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4830 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | }; |
| 4832 | unsigned long now = jiffies; |
| 4833 | int status; |
| 4834 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4835 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | if (status < 0) |
| 4837 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4838 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | return 0; |
| 4840 | } |
| 4841 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4842 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4843 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4844 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4847 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4848 | * 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] | 4849 | * the stack. |
| 4850 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4851 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4852 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4853 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4854 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4855 | { |
| 4856 | struct page *newpage, **spages; |
| 4857 | int rc = 0; |
| 4858 | size_t len; |
| 4859 | spages = pages; |
| 4860 | |
| 4861 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4862 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4863 | newpage = alloc_page(GFP_KERNEL); |
| 4864 | |
| 4865 | if (newpage == NULL) |
| 4866 | goto unwind; |
| 4867 | memcpy(page_address(newpage), buf, len); |
| 4868 | buf += len; |
| 4869 | buflen -= len; |
| 4870 | *pages++ = newpage; |
| 4871 | rc++; |
| 4872 | } while (buflen != 0); |
| 4873 | |
| 4874 | return rc; |
| 4875 | |
| 4876 | unwind: |
| 4877 | for(; rc > 0; rc--) |
| 4878 | __free_page(spages[rc-1]); |
| 4879 | return -ENOMEM; |
| 4880 | } |
| 4881 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4882 | struct nfs4_cached_acl { |
| 4883 | int cached; |
| 4884 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4885 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4886 | }; |
| 4887 | |
| 4888 | 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] | 4889 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4890 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4891 | |
| 4892 | spin_lock(&inode->i_lock); |
| 4893 | kfree(nfsi->nfs4_acl); |
| 4894 | nfsi->nfs4_acl = acl; |
| 4895 | spin_unlock(&inode->i_lock); |
| 4896 | } |
| 4897 | |
| 4898 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4899 | { |
| 4900 | nfs4_set_cached_acl(inode, NULL); |
| 4901 | } |
| 4902 | |
| 4903 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4904 | { |
| 4905 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4906 | struct nfs4_cached_acl *acl; |
| 4907 | int ret = -ENOENT; |
| 4908 | |
| 4909 | spin_lock(&inode->i_lock); |
| 4910 | acl = nfsi->nfs4_acl; |
| 4911 | if (acl == NULL) |
| 4912 | goto out; |
| 4913 | if (buf == NULL) /* user is just asking for length */ |
| 4914 | goto out_len; |
| 4915 | if (acl->cached == 0) |
| 4916 | goto out; |
| 4917 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4918 | if (acl->len > buflen) |
| 4919 | goto out; |
| 4920 | memcpy(buf, acl->data, acl->len); |
| 4921 | out_len: |
| 4922 | ret = acl->len; |
| 4923 | out: |
| 4924 | spin_unlock(&inode->i_lock); |
| 4925 | return ret; |
| 4926 | } |
| 4927 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4928 | 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] | 4929 | { |
| 4930 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4931 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4932 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4933 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4934 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4935 | if (acl == NULL) |
| 4936 | goto out; |
| 4937 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4938 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4939 | } else { |
| 4940 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4941 | if (acl == NULL) |
| 4942 | goto out; |
| 4943 | acl->cached = 0; |
| 4944 | } |
| 4945 | acl->len = acl_len; |
| 4946 | out: |
| 4947 | nfs4_set_cached_acl(inode, acl); |
| 4948 | } |
| 4949 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4950 | /* |
| 4951 | * The getxattr API returns the required buffer length when called with a |
| 4952 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4953 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4954 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4955 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4956 | * the cache. If not so, we throw away the page, and cache the required |
| 4957 | * length. The next getxattr call will then produce another round trip to |
| 4958 | * the server, this time with the input buf of the required size. |
| 4959 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4960 | 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] | 4961 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4962 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4963 | struct nfs_getaclargs args = { |
| 4964 | .fh = NFS_FH(inode), |
| 4965 | .acl_pages = pages, |
| 4966 | .acl_len = buflen, |
| 4967 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4968 | struct nfs_getaclres res = { |
| 4969 | .acl_len = buflen, |
| 4970 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4971 | struct rpc_message msg = { |
| 4972 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4973 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4974 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4975 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4976 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4977 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4978 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4979 | /* As long as we're doing a round trip to the server anyway, |
| 4980 | * let's be prepared for a page of acl data. */ |
| 4981 | if (npages == 0) |
| 4982 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4983 | if (npages > ARRAY_SIZE(pages)) |
| 4984 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4985 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4986 | for (i = 0; i < npages; i++) { |
| 4987 | pages[i] = alloc_page(GFP_KERNEL); |
| 4988 | if (!pages[i]) |
| 4989 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4990 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4991 | |
| 4992 | /* for decoding across pages */ |
| 4993 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4994 | if (!res.acl_scratch) |
| 4995 | goto out_free; |
| 4996 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4997 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4998 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4999 | 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] | 5000 | __func__, buf, buflen, npages, args.acl_len); |
| 5001 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5002 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5003 | if (ret) |
| 5004 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5005 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5006 | /* Handle the case where the passed-in buffer is too short */ |
| 5007 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5008 | /* Did the user only issue a request for the acl length? */ |
| 5009 | if (buf == NULL) |
| 5010 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5011 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5012 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5013 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5014 | 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] | 5015 | if (buf) { |
| 5016 | if (res.acl_len > buflen) { |
| 5017 | ret = -ERANGE; |
| 5018 | goto out_free; |
| 5019 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5020 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5021 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5022 | out_ok: |
| 5023 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5024 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5025 | for (i = 0; i < npages; i++) |
| 5026 | if (pages[i]) |
| 5027 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5028 | if (res.acl_scratch) |
| 5029 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5030 | return ret; |
| 5031 | } |
| 5032 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5033 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5034 | { |
| 5035 | struct nfs4_exception exception = { }; |
| 5036 | ssize_t ret; |
| 5037 | do { |
| 5038 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5039 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5040 | if (ret >= 0) |
| 5041 | break; |
| 5042 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5043 | } while (exception.retry); |
| 5044 | return ret; |
| 5045 | } |
| 5046 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5047 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5048 | { |
| 5049 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5050 | int ret; |
| 5051 | |
| 5052 | if (!nfs4_server_supports_acls(server)) |
| 5053 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5054 | ret = nfs_revalidate_inode(server, inode); |
| 5055 | if (ret < 0) |
| 5056 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5057 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5058 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5059 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5060 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5061 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5062 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5063 | return ret; |
| 5064 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5067 | 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] | 5068 | { |
| 5069 | struct nfs_server *server = NFS_SERVER(inode); |
| 5070 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5071 | struct nfs_setaclargs arg = { |
| 5072 | .fh = NFS_FH(inode), |
| 5073 | .acl_pages = pages, |
| 5074 | .acl_len = buflen, |
| 5075 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5076 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5077 | struct rpc_message msg = { |
| 5078 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5079 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5080 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5081 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5082 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5083 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5084 | |
| 5085 | if (!nfs4_server_supports_acls(server)) |
| 5086 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5087 | if (npages > ARRAY_SIZE(pages)) |
| 5088 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5089 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5090 | if (i < 0) |
| 5091 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5092 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5093 | 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] | 5094 | |
| 5095 | /* |
| 5096 | * Free each page after tx, so the only ref left is |
| 5097 | * held by the network stack |
| 5098 | */ |
| 5099 | for (; i > 0; i--) |
| 5100 | put_page(pages[i-1]); |
| 5101 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5102 | /* |
| 5103 | * Acl update can result in inode attribute update. |
| 5104 | * so mark the attribute cache invalid. |
| 5105 | */ |
| 5106 | spin_lock(&inode->i_lock); |
| 5107 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5108 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5109 | nfs_access_zap_cache(inode); |
| 5110 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5111 | return ret; |
| 5112 | } |
| 5113 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5114 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5115 | { |
| 5116 | struct nfs4_exception exception = { }; |
| 5117 | int err; |
| 5118 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5119 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5120 | trace_nfs4_set_acl(inode, err); |
| 5121 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5122 | &exception); |
| 5123 | } while (exception.retry); |
| 5124 | return err; |
| 5125 | } |
| 5126 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5127 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5128 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5129 | size_t buflen) |
| 5130 | { |
| 5131 | struct nfs_server *server = NFS_SERVER(inode); |
| 5132 | struct nfs_fattr fattr; |
| 5133 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5134 | |
| 5135 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5136 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5137 | .fh = NFS_FH(inode), |
| 5138 | .bitmask = bitmask, |
| 5139 | }; |
| 5140 | struct nfs4_getattr_res res = { |
| 5141 | .fattr = &fattr, |
| 5142 | .label = &label, |
| 5143 | .server = server, |
| 5144 | }; |
| 5145 | struct rpc_message msg = { |
| 5146 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5147 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5148 | .rpc_resp = &res, |
| 5149 | }; |
| 5150 | int ret; |
| 5151 | |
| 5152 | nfs_fattr_init(&fattr); |
| 5153 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5154 | 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] | 5155 | if (ret) |
| 5156 | return ret; |
| 5157 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5158 | return -ENOENT; |
| 5159 | if (buflen < label.len) |
| 5160 | return -ERANGE; |
| 5161 | return 0; |
| 5162 | } |
| 5163 | |
| 5164 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5165 | size_t buflen) |
| 5166 | { |
| 5167 | struct nfs4_exception exception = { }; |
| 5168 | int err; |
| 5169 | |
| 5170 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5171 | return -EOPNOTSUPP; |
| 5172 | |
| 5173 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5174 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5175 | trace_nfs4_get_security_label(inode, err); |
| 5176 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5177 | &exception); |
| 5178 | } while (exception.retry); |
| 5179 | return err; |
| 5180 | } |
| 5181 | |
| 5182 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5183 | struct nfs4_label *ilabel, |
| 5184 | struct nfs_fattr *fattr, |
| 5185 | struct nfs4_label *olabel) |
| 5186 | { |
| 5187 | |
| 5188 | struct iattr sattr = {0}; |
| 5189 | struct nfs_server *server = NFS_SERVER(inode); |
| 5190 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5191 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5192 | .fh = NFS_FH(inode), |
| 5193 | .iap = &sattr, |
| 5194 | .server = server, |
| 5195 | .bitmask = bitmask, |
| 5196 | .label = ilabel, |
| 5197 | }; |
| 5198 | struct nfs_setattrres res = { |
| 5199 | .fattr = fattr, |
| 5200 | .label = olabel, |
| 5201 | .server = server, |
| 5202 | }; |
| 5203 | struct rpc_message msg = { |
| 5204 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5205 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5206 | .rpc_resp = &res, |
| 5207 | }; |
| 5208 | int status; |
| 5209 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5210 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5211 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5212 | 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] | 5213 | if (status) |
| 5214 | dprintk("%s failed: %d\n", __func__, status); |
| 5215 | |
| 5216 | return status; |
| 5217 | } |
| 5218 | |
| 5219 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5220 | struct nfs4_label *ilabel, |
| 5221 | struct nfs_fattr *fattr, |
| 5222 | struct nfs4_label *olabel) |
| 5223 | { |
| 5224 | struct nfs4_exception exception = { }; |
| 5225 | int err; |
| 5226 | |
| 5227 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5228 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5229 | fattr, olabel); |
| 5230 | trace_nfs4_set_security_label(inode, err); |
| 5231 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5232 | &exception); |
| 5233 | } while (exception.retry); |
| 5234 | return err; |
| 5235 | } |
| 5236 | |
| 5237 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5238 | 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] | 5239 | { |
| 5240 | struct nfs4_label ilabel, *olabel = NULL; |
| 5241 | struct nfs_fattr fattr; |
| 5242 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5243 | int status; |
| 5244 | |
| 5245 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5246 | return -EOPNOTSUPP; |
| 5247 | |
| 5248 | nfs_fattr_init(&fattr); |
| 5249 | |
| 5250 | ilabel.pi = 0; |
| 5251 | ilabel.lfs = 0; |
| 5252 | ilabel.label = (char *)buf; |
| 5253 | ilabel.len = buflen; |
| 5254 | |
| 5255 | cred = rpc_lookup_cred(); |
| 5256 | if (IS_ERR(cred)) |
| 5257 | return PTR_ERR(cred); |
| 5258 | |
| 5259 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5260 | if (IS_ERR(olabel)) { |
| 5261 | status = -PTR_ERR(olabel); |
| 5262 | goto out; |
| 5263 | } |
| 5264 | |
| 5265 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5266 | if (status == 0) |
| 5267 | nfs_setsecurity(inode, &fattr, olabel); |
| 5268 | |
| 5269 | nfs4_label_free(olabel); |
| 5270 | out: |
| 5271 | put_rpccred(cred); |
| 5272 | return status; |
| 5273 | } |
| 5274 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5275 | |
| 5276 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5277 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5278 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5279 | { |
| 5280 | __be32 verf[2]; |
| 5281 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5282 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5283 | /* An impossible timestamp guarantees this value |
| 5284 | * will never match a generated boot time. */ |
| 5285 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5286 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5287 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5288 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5289 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5290 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5291 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5292 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5293 | } |
| 5294 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5295 | static int |
| 5296 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5297 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5298 | size_t len; |
| 5299 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5300 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5301 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5302 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5303 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5304 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5305 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5306 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5307 | 1 + |
| 5308 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5309 | 1; |
| 5310 | rcu_read_unlock(); |
| 5311 | |
| 5312 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5313 | return -EINVAL; |
| 5314 | |
| 5315 | /* |
| 5316 | * Since this string is allocated at mount time, and held until the |
| 5317 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5318 | * about a memory-reclaim deadlock. |
| 5319 | */ |
| 5320 | str = kmalloc(len, GFP_KERNEL); |
| 5321 | if (!str) |
| 5322 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5323 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5324 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5325 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5326 | clp->cl_ipaddr, |
| 5327 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5328 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5329 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5330 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5331 | clp->cl_owner_id = str; |
| 5332 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5333 | } |
| 5334 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5335 | static int |
| 5336 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5337 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5338 | size_t len; |
| 5339 | char *str; |
| 5340 | |
| 5341 | len = 10 + 10 + 1 + 10 + 1 + |
| 5342 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5343 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5344 | |
| 5345 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5346 | return -EINVAL; |
| 5347 | |
| 5348 | /* |
| 5349 | * Since this string is allocated at mount time, and held until the |
| 5350 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5351 | * about a memory-reclaim deadlock. |
| 5352 | */ |
| 5353 | str = kmalloc(len, GFP_KERNEL); |
| 5354 | if (!str) |
| 5355 | return -ENOMEM; |
| 5356 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5357 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5358 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5359 | nfs4_client_id_uniquifier, |
| 5360 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5361 | clp->cl_owner_id = str; |
| 5362 | return 0; |
| 5363 | } |
| 5364 | |
| 5365 | static int |
| 5366 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5367 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5368 | size_t len; |
| 5369 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5370 | |
| 5371 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5372 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5373 | |
| 5374 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5375 | return nfs4_init_uniquifier_client_string(clp); |
| 5376 | |
| 5377 | len = 10 + 10 + 1 + 10 + 1 + |
| 5378 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5379 | |
| 5380 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5381 | return -EINVAL; |
| 5382 | |
| 5383 | /* |
| 5384 | * Since this string is allocated at mount time, and held until the |
| 5385 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5386 | * about a memory-reclaim deadlock. |
| 5387 | */ |
| 5388 | str = kmalloc(len, GFP_KERNEL); |
| 5389 | if (!str) |
| 5390 | return -ENOMEM; |
| 5391 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5392 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5393 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5394 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5395 | clp->cl_owner_id = str; |
| 5396 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5397 | } |
| 5398 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5399 | /* |
| 5400 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5401 | * services. Advertise one based on the address family of the |
| 5402 | * clientaddr. |
| 5403 | */ |
| 5404 | static unsigned int |
| 5405 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5406 | { |
| 5407 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5408 | return scnprintf(buf, len, "tcp6"); |
| 5409 | else |
| 5410 | return scnprintf(buf, len, "tcp"); |
| 5411 | } |
| 5412 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5413 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5414 | { |
| 5415 | struct nfs4_setclientid *sc = calldata; |
| 5416 | |
| 5417 | if (task->tk_status == 0) |
| 5418 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5419 | } |
| 5420 | |
| 5421 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5422 | .rpc_call_done = nfs4_setclientid_done, |
| 5423 | }; |
| 5424 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5425 | /** |
| 5426 | * nfs4_proc_setclientid - Negotiate client ID |
| 5427 | * @clp: state data structure |
| 5428 | * @program: RPC program for NFSv4 callback service |
| 5429 | * @port: IP port number for NFS4 callback service |
| 5430 | * @cred: RPC credential to use for this call |
| 5431 | * @res: where to place the result |
| 5432 | * |
| 5433 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5434 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5435 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5436 | unsigned short port, struct rpc_cred *cred, |
| 5437 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | { |
| 5439 | nfs4_verifier sc_verifier; |
| 5440 | struct nfs4_setclientid setclientid = { |
| 5441 | .sc_verifier = &sc_verifier, |
| 5442 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5443 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | }; |
| 5445 | struct rpc_message msg = { |
| 5446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5447 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5448 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5449 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5451 | struct rpc_task *task; |
| 5452 | struct rpc_task_setup task_setup_data = { |
| 5453 | .rpc_client = clp->cl_rpcclient, |
| 5454 | .rpc_message = &msg, |
| 5455 | .callback_ops = &nfs4_setclientid_ops, |
| 5456 | .callback_data = &setclientid, |
| 5457 | .flags = RPC_TASK_TIMEOUT, |
| 5458 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5459 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5461 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5462 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5463 | |
| 5464 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5465 | status = nfs4_init_uniform_client_string(clp); |
| 5466 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5467 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5468 | |
| 5469 | if (status) |
| 5470 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5471 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5472 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5473 | setclientid.sc_netid_len = |
| 5474 | nfs4_init_callback_netid(clp, |
| 5475 | setclientid.sc_netid, |
| 5476 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5477 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5478 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5480 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5481 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5482 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5483 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5484 | task = rpc_run_task(&task_setup_data); |
| 5485 | if (IS_ERR(task)) { |
| 5486 | status = PTR_ERR(task); |
| 5487 | goto out; |
| 5488 | } |
| 5489 | status = task->tk_status; |
| 5490 | if (setclientid.sc_cred) { |
| 5491 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5492 | put_rpccred(setclientid.sc_cred); |
| 5493 | } |
| 5494 | rpc_put_task(task); |
| 5495 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5496 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5497 | dprintk("NFS reply setclientid: %d\n", status); |
| 5498 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | } |
| 5500 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5501 | /** |
| 5502 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5503 | * @clp: state data structure |
| 5504 | * @res: result of a previous SETCLIENTID |
| 5505 | * @cred: RPC credential to use for this call |
| 5506 | * |
| 5507 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5508 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5509 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5510 | struct nfs4_setclientid_res *arg, |
| 5511 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | struct rpc_message msg = { |
| 5514 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5515 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5516 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | int status; |
| 5519 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5520 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5521 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5522 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5523 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5524 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5525 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | return status; |
| 5527 | } |
| 5528 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5529 | struct nfs4_delegreturndata { |
| 5530 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5531 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5532 | struct nfs_fh fh; |
| 5533 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5534 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5535 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5536 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5537 | struct inode *inode; |
| 5538 | bool roc; |
| 5539 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5540 | }; |
| 5541 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5542 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5543 | { |
| 5544 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5545 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5546 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5547 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5548 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5549 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5550 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5551 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5552 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5553 | case -NFS4ERR_ADMIN_REVOKED: |
| 5554 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5555 | case -NFS4ERR_EXPIRED: |
| 5556 | nfs4_free_revoked_stateid(data->res.server, |
| 5557 | data->args.stateid, |
| 5558 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5559 | case -NFS4ERR_BAD_STATEID: |
| 5560 | case -NFS4ERR_OLD_STATEID: |
| 5561 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5562 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5563 | if (data->roc) |
| 5564 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5565 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5566 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5567 | if (nfs4_async_handle_error(task, data->res.server, |
| 5568 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5569 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5570 | return; |
| 5571 | } |
| 5572 | } |
| 5573 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | static void nfs4_delegreturn_release(void *calldata) |
| 5577 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5578 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5579 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5580 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5581 | if (inode) { |
| 5582 | if (data->roc) |
| 5583 | pnfs_roc_release(inode); |
| 5584 | nfs_iput_and_deactive(inode); |
| 5585 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5586 | kfree(calldata); |
| 5587 | } |
| 5588 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5589 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5590 | { |
| 5591 | struct nfs4_delegreturndata *d_data; |
| 5592 | |
| 5593 | d_data = (struct nfs4_delegreturndata *)data; |
| 5594 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5595 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5596 | return; |
| 5597 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5598 | if (d_data->roc) |
| 5599 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5600 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5601 | nfs4_setup_sequence(d_data->res.server, |
| 5602 | &d_data->args.seq_args, |
| 5603 | &d_data->res.seq_res, |
| 5604 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5605 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5606 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5607 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5608 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5609 | .rpc_call_done = nfs4_delegreturn_done, |
| 5610 | .rpc_release = nfs4_delegreturn_release, |
| 5611 | }; |
| 5612 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5613 | 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] | 5614 | { |
| 5615 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5616 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5617 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5618 | struct rpc_message msg = { |
| 5619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5620 | .rpc_cred = cred, |
| 5621 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5622 | struct rpc_task_setup task_setup_data = { |
| 5623 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5624 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5625 | .callback_ops = &nfs4_delegreturn_ops, |
| 5626 | .flags = RPC_TASK_ASYNC, |
| 5627 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5628 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5629 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5630 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5631 | if (data == NULL) |
| 5632 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5633 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5634 | |
| 5635 | nfs4_state_protect(server->nfs_client, |
| 5636 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5637 | &task_setup_data.rpc_client, &msg); |
| 5638 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5639 | data->args.fhandle = &data->fh; |
| 5640 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5641 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5642 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5643 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5644 | data->res.fattr = &data->fattr; |
| 5645 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5646 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5647 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5648 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5649 | data->inode = nfs_igrab_and_active(inode); |
| 5650 | if (data->inode) |
| 5651 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5652 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5653 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5654 | msg.rpc_argp = &data->args; |
| 5655 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5656 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5657 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5658 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5659 | if (!issync) |
| 5660 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5661 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5662 | if (status != 0) |
| 5663 | goto out; |
| 5664 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5665 | if (status == 0) |
| 5666 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5667 | else |
| 5668 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5669 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5670 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5671 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | } |
| 5673 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5674 | 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] | 5675 | { |
| 5676 | struct nfs_server *server = NFS_SERVER(inode); |
| 5677 | struct nfs4_exception exception = { }; |
| 5678 | int err; |
| 5679 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5680 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5681 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | switch (err) { |
| 5683 | case -NFS4ERR_STALE_STATEID: |
| 5684 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | case 0: |
| 5686 | return 0; |
| 5687 | } |
| 5688 | err = nfs4_handle_exception(server, err, &exception); |
| 5689 | } while (exception.retry); |
| 5690 | return err; |
| 5691 | } |
| 5692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5694 | { |
| 5695 | struct inode *inode = state->inode; |
| 5696 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5697 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5698 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5700 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5702 | struct nfs_lockt_res res = { |
| 5703 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | }; |
| 5705 | struct rpc_message msg = { |
| 5706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5707 | .rpc_argp = &arg, |
| 5708 | .rpc_resp = &res, |
| 5709 | .rpc_cred = state->owner->so_cred, |
| 5710 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | struct nfs4_lock_state *lsp; |
| 5712 | int status; |
| 5713 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5714 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5715 | status = nfs4_set_lock_state(state, request); |
| 5716 | if (status != 0) |
| 5717 | goto out; |
| 5718 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5719 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5720 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5721 | 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] | 5722 | switch (status) { |
| 5723 | case 0: |
| 5724 | request->fl_type = F_UNLCK; |
| 5725 | break; |
| 5726 | case -NFS4ERR_DENIED: |
| 5727 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5729 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5730 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5731 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | return status; |
| 5733 | } |
| 5734 | |
| 5735 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5736 | { |
| 5737 | struct nfs4_exception exception = { }; |
| 5738 | int err; |
| 5739 | |
| 5740 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5741 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5742 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5743 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | &exception); |
| 5745 | } while (exception.retry); |
| 5746 | return err; |
| 5747 | } |
| 5748 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5749 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5750 | struct nfs_locku_args arg; |
| 5751 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5752 | struct nfs4_lock_state *lsp; |
| 5753 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5754 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5755 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5756 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5757 | }; |
| 5758 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5759 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5760 | struct nfs_open_context *ctx, |
| 5761 | struct nfs4_lock_state *lsp, |
| 5762 | struct nfs_seqid *seqid) |
| 5763 | { |
| 5764 | struct nfs4_unlockdata *p; |
| 5765 | struct inode *inode = lsp->ls_state->inode; |
| 5766 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5767 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5768 | if (p == NULL) |
| 5769 | return NULL; |
| 5770 | p->arg.fh = NFS_FH(inode); |
| 5771 | p->arg.fl = &p->fl; |
| 5772 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5773 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5774 | p->lsp = lsp; |
| 5775 | atomic_inc(&lsp->ls_count); |
| 5776 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5777 | p->ctx = get_nfs_open_context(ctx); |
| 5778 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5779 | p->server = NFS_SERVER(inode); |
| 5780 | return p; |
| 5781 | } |
| 5782 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5783 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5784 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5785 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5786 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5787 | nfs4_put_lock_state(calldata->lsp); |
| 5788 | put_nfs_open_context(calldata->ctx); |
| 5789 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5792 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5793 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5794 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5795 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5796 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5797 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5798 | switch (task->tk_status) { |
| 5799 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5800 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5801 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5802 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5803 | &calldata->res.stateid)) |
| 5804 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5805 | case -NFS4ERR_ADMIN_REVOKED: |
| 5806 | case -NFS4ERR_EXPIRED: |
| 5807 | nfs4_free_revoked_stateid(calldata->server, |
| 5808 | &calldata->arg.stateid, |
| 5809 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5810 | case -NFS4ERR_BAD_STATEID: |
| 5811 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5812 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5813 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5814 | &calldata->lsp->ls_stateid)) |
| 5815 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5816 | break; |
| 5817 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5818 | if (nfs4_async_handle_error(task, calldata->server, |
| 5819 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5820 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5821 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5822 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5825 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5826 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5827 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5829 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5830 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5831 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5832 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5833 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5834 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5835 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5836 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5837 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5838 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5839 | &calldata->res.seq_res, |
| 5840 | task) != 0) |
| 5841 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5842 | return; |
| 5843 | out_no_action: |
| 5844 | task->tk_action = NULL; |
| 5845 | out_wait: |
| 5846 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | } |
| 5848 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5849 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5850 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5851 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5852 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5853 | }; |
| 5854 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5855 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5856 | struct nfs_open_context *ctx, |
| 5857 | struct nfs4_lock_state *lsp, |
| 5858 | struct nfs_seqid *seqid) |
| 5859 | { |
| 5860 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5861 | struct rpc_message msg = { |
| 5862 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5863 | .rpc_cred = ctx->cred, |
| 5864 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5865 | struct rpc_task_setup task_setup_data = { |
| 5866 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5867 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5868 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5869 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5870 | .flags = RPC_TASK_ASYNC, |
| 5871 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5872 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5873 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5874 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5875 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5876 | /* Ensure this is an unlock - when canceling a lock, the |
| 5877 | * canceled lock is passed in, and it won't be an unlock. |
| 5878 | */ |
| 5879 | fl->fl_type = F_UNLCK; |
| 5880 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5881 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5882 | if (data == NULL) { |
| 5883 | nfs_free_seqid(seqid); |
| 5884 | return ERR_PTR(-ENOMEM); |
| 5885 | } |
| 5886 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5887 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5888 | msg.rpc_argp = &data->arg; |
| 5889 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5890 | task_setup_data.callback_data = data; |
| 5891 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5892 | } |
| 5893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5895 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5896 | struct inode *inode = state->inode; |
| 5897 | struct nfs4_state_owner *sp = state->owner; |
| 5898 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5899 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5900 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5901 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5902 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5903 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5904 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5906 | status = nfs4_set_lock_state(state, request); |
| 5907 | /* Unlock _before_ we do the RPC call */ |
| 5908 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5909 | /* Exclude nfs_delegation_claim_locks() */ |
| 5910 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5911 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5912 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5913 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5914 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5915 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5916 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5917 | } |
| 5918 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5919 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5920 | if (status != 0) |
| 5921 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5922 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5923 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5924 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5925 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5926 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5927 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5928 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5929 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5930 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5931 | 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] | 5932 | status = PTR_ERR(task); |
| 5933 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5934 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5935 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5936 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5937 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5938 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5939 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5940 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5943 | struct nfs4_lockdata { |
| 5944 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5945 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5946 | struct nfs4_lock_state *lsp; |
| 5947 | struct nfs_open_context *ctx; |
| 5948 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5949 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5950 | int rpc_status; |
| 5951 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5952 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5953 | }; |
| 5954 | |
| 5955 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5956 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5957 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5958 | { |
| 5959 | struct nfs4_lockdata *p; |
| 5960 | struct inode *inode = lsp->ls_state->inode; |
| 5961 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5962 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5963 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5964 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5965 | if (p == NULL) |
| 5966 | return NULL; |
| 5967 | |
| 5968 | p->arg.fh = NFS_FH(inode); |
| 5969 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5970 | 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] | 5971 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5972 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5973 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5974 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5975 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5976 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5977 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5978 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5979 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5980 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5981 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5982 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5983 | atomic_inc(&lsp->ls_count); |
| 5984 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5985 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5986 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5987 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5988 | out_free_seqid: |
| 5989 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5990 | out_free: |
| 5991 | kfree(p); |
| 5992 | return NULL; |
| 5993 | } |
| 5994 | |
| 5995 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5996 | { |
| 5997 | struct nfs4_lockdata *data = calldata; |
| 5998 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5999 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6000 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6001 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6002 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6003 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6004 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6005 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6006 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6007 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6008 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6009 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6010 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6011 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6012 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6013 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6014 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6015 | &data->lsp->ls_stateid); |
| 6016 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6017 | if (!nfs4_valid_open_stateid(state)) { |
| 6018 | data->rpc_status = -EBADF; |
| 6019 | task->tk_action = NULL; |
| 6020 | goto out_release_open_seqid; |
| 6021 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6022 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6023 | if (nfs4_setup_sequence(data->server, |
| 6024 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6025 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6026 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6027 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6028 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6029 | nfs_release_seqid(data->arg.open_seqid); |
| 6030 | out_release_lock_seqid: |
| 6031 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6032 | out_wait: |
| 6033 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6034 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6035 | } |
| 6036 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6037 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6038 | { |
| 6039 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6040 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6041 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6042 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6043 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6044 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6045 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6046 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6047 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6048 | switch (task->tk_status) { |
| 6049 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6050 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6051 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6052 | if (data->arg.new_lock) { |
| 6053 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6054 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6055 | rpc_restart_call_prepare(task); |
| 6056 | break; |
| 6057 | } |
| 6058 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6059 | if (data->arg.new_lock_owner != 0) { |
| 6060 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6061 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6062 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6063 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6064 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6065 | break; |
| 6066 | case -NFS4ERR_BAD_STATEID: |
| 6067 | case -NFS4ERR_OLD_STATEID: |
| 6068 | case -NFS4ERR_STALE_STATEID: |
| 6069 | case -NFS4ERR_EXPIRED: |
| 6070 | if (data->arg.new_lock_owner != 0) { |
| 6071 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6072 | &lsp->ls_state->open_stateid)) |
| 6073 | rpc_restart_call_prepare(task); |
| 6074 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6075 | &lsp->ls_stateid)) |
| 6076 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6077 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6078 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | static void nfs4_lock_release(void *calldata) |
| 6082 | { |
| 6083 | struct nfs4_lockdata *data = calldata; |
| 6084 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6085 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6086 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6087 | if (data->cancelled != 0) { |
| 6088 | struct rpc_task *task; |
| 6089 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6090 | data->arg.lock_seqid); |
| 6091 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6092 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6093 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6094 | } else |
| 6095 | nfs_free_seqid(data->arg.lock_seqid); |
| 6096 | nfs4_put_lock_state(data->lsp); |
| 6097 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6098 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6099 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6100 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6104 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6105 | .rpc_call_done = nfs4_lock_done, |
| 6106 | .rpc_release = nfs4_lock_release, |
| 6107 | }; |
| 6108 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6109 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6110 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6111 | switch (error) { |
| 6112 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6113 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6114 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6115 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6116 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6117 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6118 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6119 | break; |
| 6120 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6121 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6122 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6123 | }; |
| 6124 | } |
| 6125 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6126 | 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] | 6127 | { |
| 6128 | struct nfs4_lockdata *data; |
| 6129 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6130 | struct rpc_message msg = { |
| 6131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6132 | .rpc_cred = state->owner->so_cred, |
| 6133 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6134 | struct rpc_task_setup task_setup_data = { |
| 6135 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6136 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6137 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6138 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6139 | .flags = RPC_TASK_ASYNC, |
| 6140 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6141 | int ret; |
| 6142 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6143 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6144 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6145 | fl->fl_u.nfs4_fl.owner, |
| 6146 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6147 | if (data == NULL) |
| 6148 | return -ENOMEM; |
| 6149 | if (IS_SETLKW(cmd)) |
| 6150 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6151 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6152 | msg.rpc_argp = &data->arg; |
| 6153 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6154 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6155 | if (recovery_type > NFS_LOCK_NEW) { |
| 6156 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6157 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6158 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6159 | } else |
| 6160 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6161 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6162 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6163 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6164 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6165 | if (ret == 0) { |
| 6166 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6167 | if (ret) |
| 6168 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6169 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6170 | } else |
| 6171 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6172 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6173 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6174 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6175 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6179 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6180 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6181 | struct nfs4_exception exception = { |
| 6182 | .inode = state->inode, |
| 6183 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6184 | int err; |
| 6185 | |
| 6186 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6187 | /* Cache the lock if possible... */ |
| 6188 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6189 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6190 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6191 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6192 | break; |
| 6193 | nfs4_handle_exception(server, err, &exception); |
| 6194 | } while (exception.retry); |
| 6195 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6199 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6200 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6201 | struct nfs4_exception exception = { |
| 6202 | .inode = state->inode, |
| 6203 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6204 | int err; |
| 6205 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6206 | err = nfs4_set_lock_state(state, request); |
| 6207 | if (err != 0) |
| 6208 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6209 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6210 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6211 | return 0; |
| 6212 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6213 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6214 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6215 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6216 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6217 | switch (err) { |
| 6218 | default: |
| 6219 | goto out; |
| 6220 | case -NFS4ERR_GRACE: |
| 6221 | case -NFS4ERR_DELAY: |
| 6222 | nfs4_handle_exception(server, err, &exception); |
| 6223 | err = 0; |
| 6224 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6225 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6226 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6227 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | } |
| 6229 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6230 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6231 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6232 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6233 | struct nfs4_lock_state *lsp; |
| 6234 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6235 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6236 | status = nfs4_set_lock_state(state, request); |
| 6237 | if (status != 0) |
| 6238 | return status; |
| 6239 | lsp = request->fl_u.nfs4_fl.owner; |
| 6240 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6241 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6242 | return 0; |
| 6243 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6244 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6245 | } |
| 6246 | #endif |
| 6247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6249 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6250 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6251 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6252 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6253 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6255 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6256 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6257 | if (status < 0) |
| 6258 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6259 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6260 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6261 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6262 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6263 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6264 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6265 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6266 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6267 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6268 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6269 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6270 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6271 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6272 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6273 | out: |
| 6274 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | return status; |
| 6276 | } |
| 6277 | |
| 6278 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6279 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6280 | struct nfs4_exception exception = { |
| 6281 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6282 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6283 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | int err; |
| 6285 | |
| 6286 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6287 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6288 | if (err == -NFS4ERR_DENIED) |
| 6289 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6291 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6292 | } while (exception.retry); |
| 6293 | return err; |
| 6294 | } |
| 6295 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6296 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6297 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6298 | |
| 6299 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6300 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6301 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6302 | { |
| 6303 | int status = -ERESTARTSYS; |
| 6304 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6305 | |
| 6306 | while(!signalled()) { |
| 6307 | status = nfs4_proc_setlk(state, cmd, request); |
| 6308 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6309 | break; |
| 6310 | freezable_schedule_timeout_interruptible(timeout); |
| 6311 | timeout *= 2; |
| 6312 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6313 | status = -ERESTARTSYS; |
| 6314 | } |
| 6315 | return status; |
| 6316 | } |
| 6317 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6318 | #ifdef CONFIG_NFS_V4_1 |
| 6319 | struct nfs4_lock_waiter { |
| 6320 | struct task_struct *task; |
| 6321 | struct inode *inode; |
| 6322 | struct nfs_lowner *owner; |
| 6323 | bool notified; |
| 6324 | }; |
| 6325 | |
| 6326 | static int |
| 6327 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6328 | { |
| 6329 | int ret; |
| 6330 | struct cb_notify_lock_args *cbnl = key; |
| 6331 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6332 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6333 | *wowner = waiter->owner; |
| 6334 | |
| 6335 | /* Only wake if the callback was for the same owner */ |
| 6336 | if (lowner->clientid != wowner->clientid || |
| 6337 | lowner->id != wowner->id || |
| 6338 | lowner->s_dev != wowner->s_dev) |
| 6339 | return 0; |
| 6340 | |
| 6341 | /* Make sure it's for the right inode */ |
| 6342 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6343 | return 0; |
| 6344 | |
| 6345 | waiter->notified = true; |
| 6346 | |
| 6347 | /* override "private" so we can use default_wake_function */ |
| 6348 | wait->private = waiter->task; |
| 6349 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6350 | wait->private = waiter; |
| 6351 | return ret; |
| 6352 | } |
| 6353 | |
| 6354 | static int |
| 6355 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6356 | { |
| 6357 | int status = -ERESTARTSYS; |
| 6358 | unsigned long flags; |
| 6359 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6360 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6361 | struct nfs_client *clp = server->nfs_client; |
| 6362 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6363 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6364 | .id = lsp->ls_seqid.owner_id, |
| 6365 | .s_dev = server->s_dev }; |
| 6366 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6367 | .inode = state->inode, |
| 6368 | .owner = &owner, |
| 6369 | .notified = false }; |
| 6370 | wait_queue_t wait; |
| 6371 | |
| 6372 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6373 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6374 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6375 | |
| 6376 | init_wait(&wait); |
| 6377 | wait.private = &waiter; |
| 6378 | wait.func = nfs4_wake_lock_waiter; |
| 6379 | add_wait_queue(q, &wait); |
| 6380 | |
| 6381 | while(!signalled()) { |
| 6382 | status = nfs4_proc_setlk(state, cmd, request); |
| 6383 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6384 | break; |
| 6385 | |
| 6386 | status = -ERESTARTSYS; |
| 6387 | spin_lock_irqsave(&q->lock, flags); |
| 6388 | if (waiter.notified) { |
| 6389 | spin_unlock_irqrestore(&q->lock, flags); |
| 6390 | continue; |
| 6391 | } |
| 6392 | set_current_state(TASK_INTERRUPTIBLE); |
| 6393 | spin_unlock_irqrestore(&q->lock, flags); |
| 6394 | |
| 6395 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6396 | } |
| 6397 | |
| 6398 | finish_wait(q, &wait); |
| 6399 | return status; |
| 6400 | } |
| 6401 | #else /* !CONFIG_NFS_V4_1 */ |
| 6402 | static inline int |
| 6403 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6404 | { |
| 6405 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6406 | } |
| 6407 | #endif |
| 6408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6409 | static int |
| 6410 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6411 | { |
| 6412 | struct nfs_open_context *ctx; |
| 6413 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6414 | int status; |
| 6415 | |
| 6416 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6417 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | state = ctx->state; |
| 6419 | |
| 6420 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6421 | return -EINVAL; |
| 6422 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6423 | if (IS_GETLK(cmd)) { |
| 6424 | if (state != NULL) |
| 6425 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6426 | return 0; |
| 6427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6428 | |
| 6429 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6430 | return -EINVAL; |
| 6431 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6432 | if (request->fl_type == F_UNLCK) { |
| 6433 | if (state != NULL) |
| 6434 | return nfs4_proc_unlck(state, cmd, request); |
| 6435 | return 0; |
| 6436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6438 | if (state == NULL) |
| 6439 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6440 | |
| 6441 | if ((request->fl_flags & FL_POSIX) && |
| 6442 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6443 | return -ENOLCK; |
| 6444 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6445 | /* |
| 6446 | * Don't rely on the VFS having checked the file open mode, |
| 6447 | * since it won't do this for flock() locks. |
| 6448 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6449 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6450 | case F_RDLCK: |
| 6451 | if (!(filp->f_mode & FMODE_READ)) |
| 6452 | return -EBADF; |
| 6453 | break; |
| 6454 | case F_WRLCK: |
| 6455 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6456 | return -EBADF; |
| 6457 | } |
| 6458 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6459 | status = nfs4_set_lock_state(state, request); |
| 6460 | if (status != 0) |
| 6461 | return status; |
| 6462 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6463 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6466 | 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] | 6467 | { |
| 6468 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6469 | int err; |
| 6470 | |
| 6471 | err = nfs4_set_lock_state(state, fl); |
| 6472 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6473 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6474 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6475 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6476 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6477 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6478 | struct nfs_release_lockowner_data { |
| 6479 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6480 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6481 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6482 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6483 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6484 | }; |
| 6485 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6486 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6487 | { |
| 6488 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6489 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6490 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6491 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6492 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6493 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6494 | } |
| 6495 | |
| 6496 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6497 | { |
| 6498 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6499 | struct nfs_server *server = data->server; |
| 6500 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6501 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6502 | |
| 6503 | switch (task->tk_status) { |
| 6504 | case 0: |
| 6505 | renew_lease(server, data->timestamp); |
| 6506 | break; |
| 6507 | case -NFS4ERR_STALE_CLIENTID: |
| 6508 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6509 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6510 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6511 | case -NFS4ERR_LEASE_MOVED: |
| 6512 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6513 | if (nfs4_async_handle_error(task, server, |
| 6514 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6515 | rpc_restart_call_prepare(task); |
| 6516 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6517 | } |
| 6518 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6519 | static void nfs4_release_lockowner_release(void *calldata) |
| 6520 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6521 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6522 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6523 | kfree(calldata); |
| 6524 | } |
| 6525 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6526 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6527 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6528 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6529 | .rpc_release = nfs4_release_lockowner_release, |
| 6530 | }; |
| 6531 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6532 | static void |
| 6533 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6534 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6535 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6536 | struct rpc_message msg = { |
| 6537 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6538 | }; |
| 6539 | |
| 6540 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6541 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6542 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6543 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6544 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6545 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6546 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6547 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6548 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6549 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6550 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6551 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6552 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6553 | msg.rpc_resp = &data->res; |
| 6554 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6555 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6556 | } |
| 6557 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6558 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6559 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6560 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6561 | struct dentry *unused, struct inode *inode, |
| 6562 | const char *key, const void *buf, |
| 6563 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6564 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6565 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6566 | } |
| 6567 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6568 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6569 | struct dentry *unused, struct inode *inode, |
| 6570 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6571 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6572 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6575 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6576 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6577 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6578 | } |
| 6579 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6580 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6581 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6582 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6583 | struct dentry *unused, struct inode *inode, |
| 6584 | const char *key, const void *buf, |
| 6585 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6586 | { |
| 6587 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6588 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6589 | |
| 6590 | return -EOPNOTSUPP; |
| 6591 | } |
| 6592 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6593 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6594 | struct dentry *unused, struct inode *inode, |
| 6595 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6596 | { |
| 6597 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6598 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6599 | return -EOPNOTSUPP; |
| 6600 | } |
| 6601 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6602 | static ssize_t |
| 6603 | 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] | 6604 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6605 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6606 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6607 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6608 | len = security_inode_listsecurity(inode, list, list_len); |
| 6609 | if (list_len && len > list_len) |
| 6610 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6611 | } |
| 6612 | return len; |
| 6613 | } |
| 6614 | |
| 6615 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6616 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6617 | .get = nfs4_xattr_get_nfs4_label, |
| 6618 | .set = nfs4_xattr_set_nfs4_label, |
| 6619 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6620 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6621 | #else |
| 6622 | |
| 6623 | static ssize_t |
| 6624 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6625 | { |
| 6626 | return 0; |
| 6627 | } |
| 6628 | |
| 6629 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6630 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6631 | /* |
| 6632 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6633 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6634 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6635 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6636 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6637 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6638 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6639 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6640 | return; |
| 6641 | |
| 6642 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6643 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6644 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6645 | fattr->nlink = 2; |
| 6646 | } |
| 6647 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6648 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6649 | const struct qstr *name, |
| 6650 | struct nfs4_fs_locations *fs_locations, |
| 6651 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6652 | { |
| 6653 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6654 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6655 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6656 | }; |
| 6657 | struct nfs4_fs_locations_arg args = { |
| 6658 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6659 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6660 | .page = page, |
| 6661 | .bitmask = bitmask, |
| 6662 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6663 | struct nfs4_fs_locations_res res = { |
| 6664 | .fs_locations = fs_locations, |
| 6665 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6666 | struct rpc_message msg = { |
| 6667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6668 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6669 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6670 | }; |
| 6671 | int status; |
| 6672 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6673 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6674 | |
| 6675 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6676 | * is not supported */ |
| 6677 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6678 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6679 | else |
| 6680 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6681 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6682 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6683 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6684 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6685 | 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] | 6686 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6687 | return status; |
| 6688 | } |
| 6689 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6690 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6691 | const struct qstr *name, |
| 6692 | struct nfs4_fs_locations *fs_locations, |
| 6693 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6694 | { |
| 6695 | struct nfs4_exception exception = { }; |
| 6696 | int err; |
| 6697 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6698 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6699 | fs_locations, page); |
| 6700 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6701 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6702 | &exception); |
| 6703 | } while (exception.retry); |
| 6704 | return err; |
| 6705 | } |
| 6706 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6707 | /* |
| 6708 | * This operation also signals the server that this client is |
| 6709 | * performing migration recovery. The server can stop returning |
| 6710 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6711 | * appended to this compound to identify the client ID which is |
| 6712 | * performing recovery. |
| 6713 | */ |
| 6714 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6715 | struct nfs4_fs_locations *locations, |
| 6716 | struct page *page, struct rpc_cred *cred) |
| 6717 | { |
| 6718 | struct nfs_server *server = NFS_SERVER(inode); |
| 6719 | struct rpc_clnt *clnt = server->client; |
| 6720 | u32 bitmask[2] = { |
| 6721 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6722 | }; |
| 6723 | struct nfs4_fs_locations_arg args = { |
| 6724 | .clientid = server->nfs_client->cl_clientid, |
| 6725 | .fh = NFS_FH(inode), |
| 6726 | .page = page, |
| 6727 | .bitmask = bitmask, |
| 6728 | .migration = 1, /* skip LOOKUP */ |
| 6729 | .renew = 1, /* append RENEW */ |
| 6730 | }; |
| 6731 | struct nfs4_fs_locations_res res = { |
| 6732 | .fs_locations = locations, |
| 6733 | .migration = 1, |
| 6734 | .renew = 1, |
| 6735 | }; |
| 6736 | struct rpc_message msg = { |
| 6737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6738 | .rpc_argp = &args, |
| 6739 | .rpc_resp = &res, |
| 6740 | .rpc_cred = cred, |
| 6741 | }; |
| 6742 | unsigned long now = jiffies; |
| 6743 | int status; |
| 6744 | |
| 6745 | nfs_fattr_init(&locations->fattr); |
| 6746 | locations->server = server; |
| 6747 | locations->nlocations = 0; |
| 6748 | |
| 6749 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6750 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6751 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6752 | &args.seq_args, &res.seq_res); |
| 6753 | if (status) |
| 6754 | return status; |
| 6755 | |
| 6756 | renew_lease(server, now); |
| 6757 | return 0; |
| 6758 | } |
| 6759 | |
| 6760 | #ifdef CONFIG_NFS_V4_1 |
| 6761 | |
| 6762 | /* |
| 6763 | * This operation also signals the server that this client is |
| 6764 | * performing migration recovery. The server can stop asserting |
| 6765 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6766 | * performing this operation is identified in the SEQUENCE |
| 6767 | * operation in this compound. |
| 6768 | * |
| 6769 | * When the client supports GETATTR(fs_locations_info), it can |
| 6770 | * be plumbed in here. |
| 6771 | */ |
| 6772 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6773 | struct nfs4_fs_locations *locations, |
| 6774 | struct page *page, struct rpc_cred *cred) |
| 6775 | { |
| 6776 | struct nfs_server *server = NFS_SERVER(inode); |
| 6777 | struct rpc_clnt *clnt = server->client; |
| 6778 | u32 bitmask[2] = { |
| 6779 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6780 | }; |
| 6781 | struct nfs4_fs_locations_arg args = { |
| 6782 | .fh = NFS_FH(inode), |
| 6783 | .page = page, |
| 6784 | .bitmask = bitmask, |
| 6785 | .migration = 1, /* skip LOOKUP */ |
| 6786 | }; |
| 6787 | struct nfs4_fs_locations_res res = { |
| 6788 | .fs_locations = locations, |
| 6789 | .migration = 1, |
| 6790 | }; |
| 6791 | struct rpc_message msg = { |
| 6792 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6793 | .rpc_argp = &args, |
| 6794 | .rpc_resp = &res, |
| 6795 | .rpc_cred = cred, |
| 6796 | }; |
| 6797 | int status; |
| 6798 | |
| 6799 | nfs_fattr_init(&locations->fattr); |
| 6800 | locations->server = server; |
| 6801 | locations->nlocations = 0; |
| 6802 | |
| 6803 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6804 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6805 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6806 | &args.seq_args, &res.seq_res); |
| 6807 | if (status == NFS4_OK && |
| 6808 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6809 | status = -NFS4ERR_LEASE_MOVED; |
| 6810 | return status; |
| 6811 | } |
| 6812 | |
| 6813 | #endif /* CONFIG_NFS_V4_1 */ |
| 6814 | |
| 6815 | /** |
| 6816 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6817 | * @inode: inode on FSID that is migrating |
| 6818 | * @locations: result of query |
| 6819 | * @page: buffer |
| 6820 | * @cred: credential to use for this operation |
| 6821 | * |
| 6822 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6823 | * operation failed, or a negative errno if a local error occurred. |
| 6824 | * |
| 6825 | * On success, "locations" is filled in, but if the server has |
| 6826 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6827 | * asserted. |
| 6828 | * |
| 6829 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6830 | * from this client that require migration recovery. |
| 6831 | */ |
| 6832 | int nfs4_proc_get_locations(struct inode *inode, |
| 6833 | struct nfs4_fs_locations *locations, |
| 6834 | struct page *page, struct rpc_cred *cred) |
| 6835 | { |
| 6836 | struct nfs_server *server = NFS_SERVER(inode); |
| 6837 | struct nfs_client *clp = server->nfs_client; |
| 6838 | const struct nfs4_mig_recovery_ops *ops = |
| 6839 | clp->cl_mvops->mig_recovery_ops; |
| 6840 | struct nfs4_exception exception = { }; |
| 6841 | int status; |
| 6842 | |
| 6843 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6844 | (unsigned long long)server->fsid.major, |
| 6845 | (unsigned long long)server->fsid.minor, |
| 6846 | clp->cl_hostname); |
| 6847 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6848 | |
| 6849 | do { |
| 6850 | status = ops->get_locations(inode, locations, page, cred); |
| 6851 | if (status != -NFS4ERR_DELAY) |
| 6852 | break; |
| 6853 | nfs4_handle_exception(server, status, &exception); |
| 6854 | } while (exception.retry); |
| 6855 | return status; |
| 6856 | } |
| 6857 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6858 | /* |
| 6859 | * This operation also signals the server that this client is |
| 6860 | * performing "lease moved" recovery. The server can stop |
| 6861 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6862 | * is appended to this compound to identify the client ID which is |
| 6863 | * performing recovery. |
| 6864 | */ |
| 6865 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6866 | { |
| 6867 | struct nfs_server *server = NFS_SERVER(inode); |
| 6868 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6869 | struct rpc_clnt *clnt = server->client; |
| 6870 | struct nfs4_fsid_present_arg args = { |
| 6871 | .fh = NFS_FH(inode), |
| 6872 | .clientid = clp->cl_clientid, |
| 6873 | .renew = 1, /* append RENEW */ |
| 6874 | }; |
| 6875 | struct nfs4_fsid_present_res res = { |
| 6876 | .renew = 1, |
| 6877 | }; |
| 6878 | struct rpc_message msg = { |
| 6879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6880 | .rpc_argp = &args, |
| 6881 | .rpc_resp = &res, |
| 6882 | .rpc_cred = cred, |
| 6883 | }; |
| 6884 | unsigned long now = jiffies; |
| 6885 | int status; |
| 6886 | |
| 6887 | res.fh = nfs_alloc_fhandle(); |
| 6888 | if (res.fh == NULL) |
| 6889 | return -ENOMEM; |
| 6890 | |
| 6891 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6892 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6893 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6894 | &args.seq_args, &res.seq_res); |
| 6895 | nfs_free_fhandle(res.fh); |
| 6896 | if (status) |
| 6897 | return status; |
| 6898 | |
| 6899 | do_renew_lease(clp, now); |
| 6900 | return 0; |
| 6901 | } |
| 6902 | |
| 6903 | #ifdef CONFIG_NFS_V4_1 |
| 6904 | |
| 6905 | /* |
| 6906 | * This operation also signals the server that this client is |
| 6907 | * performing "lease moved" recovery. The server can stop asserting |
| 6908 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6909 | * this operation is identified in the SEQUENCE operation in this |
| 6910 | * compound. |
| 6911 | */ |
| 6912 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6913 | { |
| 6914 | struct nfs_server *server = NFS_SERVER(inode); |
| 6915 | struct rpc_clnt *clnt = server->client; |
| 6916 | struct nfs4_fsid_present_arg args = { |
| 6917 | .fh = NFS_FH(inode), |
| 6918 | }; |
| 6919 | struct nfs4_fsid_present_res res = { |
| 6920 | }; |
| 6921 | struct rpc_message msg = { |
| 6922 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6923 | .rpc_argp = &args, |
| 6924 | .rpc_resp = &res, |
| 6925 | .rpc_cred = cred, |
| 6926 | }; |
| 6927 | int status; |
| 6928 | |
| 6929 | res.fh = nfs_alloc_fhandle(); |
| 6930 | if (res.fh == NULL) |
| 6931 | return -ENOMEM; |
| 6932 | |
| 6933 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6934 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6935 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6936 | &args.seq_args, &res.seq_res); |
| 6937 | nfs_free_fhandle(res.fh); |
| 6938 | if (status == NFS4_OK && |
| 6939 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6940 | status = -NFS4ERR_LEASE_MOVED; |
| 6941 | return status; |
| 6942 | } |
| 6943 | |
| 6944 | #endif /* CONFIG_NFS_V4_1 */ |
| 6945 | |
| 6946 | /** |
| 6947 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6948 | * @inode: inode on FSID to check |
| 6949 | * @cred: credential to use for this operation |
| 6950 | * |
| 6951 | * Server indicates whether the FSID is present, moved, or not |
| 6952 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6953 | * condition for this client ID. |
| 6954 | * |
| 6955 | * Returns NFS4_OK if the FSID is present on this server, |
| 6956 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6957 | * NFS4ERR code if some error occurred on the server, or a |
| 6958 | * negative errno if a local failure occurred. |
| 6959 | */ |
| 6960 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6961 | { |
| 6962 | struct nfs_server *server = NFS_SERVER(inode); |
| 6963 | struct nfs_client *clp = server->nfs_client; |
| 6964 | const struct nfs4_mig_recovery_ops *ops = |
| 6965 | clp->cl_mvops->mig_recovery_ops; |
| 6966 | struct nfs4_exception exception = { }; |
| 6967 | int status; |
| 6968 | |
| 6969 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6970 | (unsigned long long)server->fsid.major, |
| 6971 | (unsigned long long)server->fsid.minor, |
| 6972 | clp->cl_hostname); |
| 6973 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6974 | |
| 6975 | do { |
| 6976 | status = ops->fsid_present(inode, cred); |
| 6977 | if (status != -NFS4ERR_DELAY) |
| 6978 | break; |
| 6979 | nfs4_handle_exception(server, status, &exception); |
| 6980 | } while (exception.retry); |
| 6981 | return status; |
| 6982 | } |
| 6983 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6984 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6985 | * If 'use_integrity' is true and the state managment nfs_client |
| 6986 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6987 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6988 | * Considerations sections. Otherwise, just use the user cred with the |
| 6989 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6990 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6991 | 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] | 6992 | { |
| 6993 | int status; |
| 6994 | struct nfs4_secinfo_arg args = { |
| 6995 | .dir_fh = NFS_FH(dir), |
| 6996 | .name = name, |
| 6997 | }; |
| 6998 | struct nfs4_secinfo_res res = { |
| 6999 | .flavors = flavors, |
| 7000 | }; |
| 7001 | struct rpc_message msg = { |
| 7002 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7003 | .rpc_argp = &args, |
| 7004 | .rpc_resp = &res, |
| 7005 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7006 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7007 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7008 | |
| 7009 | if (use_integrity) { |
| 7010 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7011 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7012 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7013 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7014 | |
| 7015 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7016 | |
| 7017 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7018 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7019 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7020 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7021 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7022 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7023 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7024 | if (cred) |
| 7025 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7026 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7027 | return status; |
| 7028 | } |
| 7029 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7030 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7031 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7032 | { |
| 7033 | struct nfs4_exception exception = { }; |
| 7034 | int err; |
| 7035 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7036 | err = -NFS4ERR_WRONGSEC; |
| 7037 | |
| 7038 | /* try to use integrity protection with machine cred */ |
| 7039 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7040 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7041 | |
| 7042 | /* |
| 7043 | * if unable to use integrity protection, or SECINFO with |
| 7044 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7045 | * disallowed by spec, but exists in deployed servers) use |
| 7046 | * the current filesystem's rpc_client and the user cred. |
| 7047 | */ |
| 7048 | if (err == -NFS4ERR_WRONGSEC) |
| 7049 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7050 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7051 | trace_nfs4_secinfo(dir, name, err); |
| 7052 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7053 | &exception); |
| 7054 | } while (exception.retry); |
| 7055 | return err; |
| 7056 | } |
| 7057 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7058 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7059 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7060 | * Check the exchange flags returned by the server for invalid flags, having |
| 7061 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7062 | * DS flags set. |
| 7063 | */ |
| 7064 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7065 | { |
| 7066 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7067 | goto out_inval; |
| 7068 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7069 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7070 | goto out_inval; |
| 7071 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7072 | goto out_inval; |
| 7073 | return NFS_OK; |
| 7074 | out_inval: |
| 7075 | return -NFS4ERR_INVAL; |
| 7076 | } |
| 7077 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7078 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7079 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7080 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7081 | { |
| 7082 | if (a->server_scope_sz == b->server_scope_sz && |
| 7083 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7084 | return true; |
| 7085 | |
| 7086 | return false; |
| 7087 | } |
| 7088 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7089 | static void |
| 7090 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7091 | { |
| 7092 | } |
| 7093 | |
| 7094 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7095 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7096 | }; |
| 7097 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7098 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7099 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7100 | * |
| 7101 | * The 4.1 client currently uses the same TCP connection for the |
| 7102 | * fore and backchannel. |
| 7103 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7104 | static |
| 7105 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7106 | struct rpc_xprt *xprt, |
| 7107 | struct nfs_client *clp, |
| 7108 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7109 | { |
| 7110 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7111 | struct nfs41_bind_conn_to_session_args args = { |
| 7112 | .client = clp, |
| 7113 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7114 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7115 | struct nfs41_bind_conn_to_session_res res; |
| 7116 | struct rpc_message msg = { |
| 7117 | .rpc_proc = |
| 7118 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7119 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7120 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7121 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7122 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7123 | struct rpc_task_setup task_setup_data = { |
| 7124 | .rpc_client = clnt, |
| 7125 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7126 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7127 | .rpc_message = &msg, |
| 7128 | .flags = RPC_TASK_TIMEOUT, |
| 7129 | }; |
| 7130 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7131 | |
| 7132 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7133 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7134 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7135 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7136 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7137 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7138 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7139 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7140 | args.dir = NFS4_CDFC4_FORE; |
| 7141 | |
| 7142 | task = rpc_run_task(&task_setup_data); |
| 7143 | if (!IS_ERR(task)) { |
| 7144 | status = task->tk_status; |
| 7145 | rpc_put_task(task); |
| 7146 | } else |
| 7147 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7148 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7149 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7150 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7151 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7152 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7153 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7154 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7155 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7156 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7157 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7158 | __func__); |
| 7159 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7160 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7161 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7162 | 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] | 7163 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7164 | __func__); |
| 7165 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7166 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7167 | } |
| 7168 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7169 | out: |
| 7170 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7171 | return status; |
| 7172 | } |
| 7173 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7174 | struct rpc_bind_conn_calldata { |
| 7175 | struct nfs_client *clp; |
| 7176 | struct rpc_cred *cred; |
| 7177 | }; |
| 7178 | |
| 7179 | static int |
| 7180 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7181 | struct rpc_xprt *xprt, |
| 7182 | void *calldata) |
| 7183 | { |
| 7184 | struct rpc_bind_conn_calldata *p = calldata; |
| 7185 | |
| 7186 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7187 | } |
| 7188 | |
| 7189 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7190 | { |
| 7191 | struct rpc_bind_conn_calldata data = { |
| 7192 | .clp = clp, |
| 7193 | .cred = cred, |
| 7194 | }; |
| 7195 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7196 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7197 | } |
| 7198 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7199 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7200 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7201 | * 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] | 7202 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7203 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7204 | .how = SP4_MACH_CRED, |
| 7205 | .enforce.u.words = { |
| 7206 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7207 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7208 | 1 << (OP_CREATE_SESSION - 32) | |
| 7209 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7210 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7211 | }, |
| 7212 | .allow.u.words = { |
| 7213 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7214 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7215 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7216 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7217 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7218 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7219 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7220 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7221 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7222 | 1 << (OP_FREE_STATEID - 32) | |
| 7223 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7224 | } |
| 7225 | }; |
| 7226 | |
| 7227 | /* |
| 7228 | * Select the state protection mode for client `clp' given the server results |
| 7229 | * from exchange_id in `sp'. |
| 7230 | * |
| 7231 | * Returns 0 on success, negative errno otherwise. |
| 7232 | */ |
| 7233 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7234 | struct nfs41_state_protection *sp) |
| 7235 | { |
| 7236 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7237 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7238 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7239 | 1 << (OP_CREATE_SESSION - 32) | |
| 7240 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7241 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7242 | }; |
| 7243 | unsigned int i; |
| 7244 | |
| 7245 | if (sp->how == SP4_MACH_CRED) { |
| 7246 | /* Print state protect result */ |
| 7247 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7248 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7249 | if (test_bit(i, sp->enforce.u.longs)) |
| 7250 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7251 | if (test_bit(i, sp->allow.u.longs)) |
| 7252 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7253 | } |
| 7254 | |
| 7255 | /* make sure nothing is on enforce list that isn't supported */ |
| 7256 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7257 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7258 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7259 | return -EINVAL; |
| 7260 | } |
| 7261 | } |
| 7262 | |
| 7263 | /* |
| 7264 | * Minimal mode - state operations are allowed to use machine |
| 7265 | * credential. Note this already happens by default, so the |
| 7266 | * client doesn't have to do anything more than the negotiation. |
| 7267 | * |
| 7268 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7269 | * we're already using the machine cred for exchange_id |
| 7270 | * and will never use a different cred. |
| 7271 | */ |
| 7272 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7273 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7274 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7275 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7276 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7277 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7278 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7279 | } else { |
| 7280 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7281 | return -EINVAL; |
| 7282 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7283 | |
| 7284 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7285 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7286 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7287 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7288 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7289 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7290 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7291 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7292 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7293 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7294 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7295 | &clp->cl_sp4_flags); |
| 7296 | } |
| 7297 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7298 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7299 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7300 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7301 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7302 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7303 | |
| 7304 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7305 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7306 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7307 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7308 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7309 | |
| 7310 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7311 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7312 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7313 | } |
| 7314 | |
| 7315 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7316 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7317 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7318 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | return 0; |
| 7322 | } |
| 7323 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7324 | struct nfs41_exchange_id_data { |
| 7325 | struct nfs41_exchange_id_res res; |
| 7326 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7327 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7328 | int rpc_status; |
| 7329 | }; |
| 7330 | |
| 7331 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7332 | { |
| 7333 | struct nfs41_exchange_id_data *cdata = |
| 7334 | (struct nfs41_exchange_id_data *)data; |
| 7335 | struct nfs_client *clp = cdata->args.client; |
| 7336 | int status = task->tk_status; |
| 7337 | |
| 7338 | trace_nfs4_exchange_id(clp, status); |
| 7339 | |
| 7340 | if (status == 0) |
| 7341 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7342 | |
| 7343 | if (cdata->xprt && status == 0) { |
| 7344 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7345 | cdata->xprt); |
| 7346 | goto out; |
| 7347 | } |
| 7348 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7349 | if (status == 0) |
| 7350 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7351 | |
| 7352 | if (status == 0) { |
| 7353 | clp->cl_clientid = cdata->res.clientid; |
| 7354 | clp->cl_exchange_flags = cdata->res.flags; |
| 7355 | /* Client ID is not confirmed */ |
| 7356 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7357 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7358 | &clp->cl_session->session_state); |
| 7359 | clp->cl_seqid = cdata->res.seqid; |
| 7360 | } |
| 7361 | |
| 7362 | kfree(clp->cl_serverowner); |
| 7363 | clp->cl_serverowner = cdata->res.server_owner; |
| 7364 | cdata->res.server_owner = NULL; |
| 7365 | |
| 7366 | /* use the most recent implementation id */ |
| 7367 | kfree(clp->cl_implid); |
| 7368 | clp->cl_implid = cdata->res.impl_id; |
| 7369 | cdata->res.impl_id = NULL; |
| 7370 | |
| 7371 | if (clp->cl_serverscope != NULL && |
| 7372 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7373 | cdata->res.server_scope)) { |
| 7374 | dprintk("%s: server_scope mismatch detected\n", |
| 7375 | __func__); |
| 7376 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7377 | kfree(clp->cl_serverscope); |
| 7378 | clp->cl_serverscope = NULL; |
| 7379 | } |
| 7380 | |
| 7381 | if (clp->cl_serverscope == NULL) { |
| 7382 | clp->cl_serverscope = cdata->res.server_scope; |
| 7383 | cdata->res.server_scope = NULL; |
| 7384 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7385 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7386 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7387 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7388 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7389 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7390 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7391 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | static void nfs4_exchange_id_release(void *data) |
| 7395 | { |
| 7396 | struct nfs41_exchange_id_data *cdata = |
| 7397 | (struct nfs41_exchange_id_data *)data; |
| 7398 | |
| 7399 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7400 | if (cdata->xprt) { |
| 7401 | xprt_put(cdata->xprt); |
| 7402 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7403 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7404 | kfree(cdata->res.impl_id); |
| 7405 | kfree(cdata->res.server_scope); |
| 7406 | kfree(cdata->res.server_owner); |
| 7407 | kfree(cdata); |
| 7408 | } |
| 7409 | |
| 7410 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7411 | .rpc_call_done = nfs4_exchange_id_done, |
| 7412 | .rpc_release = nfs4_exchange_id_release, |
| 7413 | }; |
| 7414 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7415 | /* |
| 7416 | * _nfs4_proc_exchange_id() |
| 7417 | * |
| 7418 | * Wrapper for EXCHANGE_ID operation. |
| 7419 | */ |
| 7420 | 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] | 7421 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7422 | { |
| 7423 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7424 | struct rpc_message msg = { |
| 7425 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7426 | .rpc_cred = cred, |
| 7427 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7428 | struct rpc_task_setup task_setup_data = { |
| 7429 | .rpc_client = clp->cl_rpcclient, |
| 7430 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7431 | .rpc_message = &msg, |
| 7432 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7433 | }; |
| 7434 | struct nfs41_exchange_id_data *calldata; |
| 7435 | struct rpc_task *task; |
| 7436 | int status = -EIO; |
| 7437 | |
| 7438 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7439 | goto out; |
| 7440 | |
| 7441 | status = -ENOMEM; |
| 7442 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7443 | if (!calldata) |
| 7444 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7445 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7446 | if (!xprt) |
| 7447 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7448 | |
| 7449 | status = nfs4_init_uniform_client_string(clp); |
| 7450 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7451 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7452 | |
| 7453 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7454 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7455 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7456 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7457 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7458 | GFP_NOFS); |
| 7459 | status = -ENOMEM; |
| 7460 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7461 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7462 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7463 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7464 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7465 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7466 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7467 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7468 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7469 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7470 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7471 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7472 | switch (sp4_how) { |
| 7473 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7474 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7475 | break; |
| 7476 | |
| 7477 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7478 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7479 | break; |
| 7480 | |
| 7481 | default: |
| 7482 | /* unsupported! */ |
| 7483 | WARN_ON_ONCE(1); |
| 7484 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7485 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7486 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7487 | if (xprt) { |
| 7488 | calldata->xprt = xprt; |
| 7489 | task_setup_data.rpc_xprt = xprt; |
| 7490 | task_setup_data.flags = |
| 7491 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7492 | calldata->args.verifier = &clp->cl_confirm; |
| 7493 | } else { |
| 7494 | calldata->args.verifier = &verifier; |
| 7495 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7496 | calldata->args.client = clp; |
| 7497 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7498 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7499 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7500 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7501 | #else |
| 7502 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7503 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7504 | #endif |
| 7505 | msg.rpc_argp = &calldata->args; |
| 7506 | msg.rpc_resp = &calldata->res; |
| 7507 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7508 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7509 | task = rpc_run_task(&task_setup_data); |
| 7510 | if (IS_ERR(task)) { |
| 7511 | status = PTR_ERR(task); |
| 7512 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7513 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7514 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7515 | if (!xprt) { |
| 7516 | status = rpc_wait_for_completion_task(task); |
| 7517 | if (!status) |
| 7518 | status = calldata->rpc_status; |
| 7519 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7520 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7521 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7522 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7523 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7524 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7525 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7526 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7527 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7528 | clp->cl_implid->date.seconds, |
| 7529 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7530 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7531 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7532 | |
| 7533 | out_impl_id: |
| 7534 | kfree(calldata->res.impl_id); |
| 7535 | out_server_scope: |
| 7536 | kfree(calldata->res.server_scope); |
| 7537 | out_server_owner: |
| 7538 | kfree(calldata->res.server_owner); |
| 7539 | out_calldata: |
| 7540 | kfree(calldata); |
| 7541 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7542 | } |
| 7543 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7544 | /* |
| 7545 | * nfs4_proc_exchange_id() |
| 7546 | * |
| 7547 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7548 | * |
| 7549 | * Since the clientid has expired, all compounds using sessions |
| 7550 | * associated with the stale clientid will be returning |
| 7551 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7552 | * be in some phase of session reset. |
| 7553 | * |
| 7554 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7555 | */ |
| 7556 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7557 | { |
| 7558 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7559 | int status; |
| 7560 | |
| 7561 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7562 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7563 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7564 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7565 | if (!status) |
| 7566 | return 0; |
| 7567 | } |
| 7568 | |
| 7569 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7570 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7571 | } |
| 7572 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7573 | /** |
| 7574 | * nfs4_test_session_trunk |
| 7575 | * |
| 7576 | * This is an add_xprt_test() test function called from |
| 7577 | * rpc_clnt_setup_test_and_add_xprt. |
| 7578 | * |
| 7579 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7580 | * and is dereferrenced in nfs4_exchange_id_release |
| 7581 | * |
| 7582 | * Upon success, add the new transport to the rpc_clnt |
| 7583 | * |
| 7584 | * @clnt: struct rpc_clnt to get new transport |
| 7585 | * @xprt: the rpc_xprt to test |
| 7586 | * @data: call data for _nfs4_proc_exchange_id. |
| 7587 | */ |
| 7588 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7589 | void *data) |
| 7590 | { |
| 7591 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7592 | u32 sp4_how; |
| 7593 | |
| 7594 | dprintk("--> %s try %s\n", __func__, |
| 7595 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7596 | |
| 7597 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7598 | |
| 7599 | /* Test connection for session trunking. Async exchange_id call */ |
| 7600 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7601 | } |
| 7602 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7603 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7604 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7605 | struct rpc_cred *cred) |
| 7606 | { |
| 7607 | struct rpc_message msg = { |
| 7608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7609 | .rpc_argp = clp, |
| 7610 | .rpc_cred = cred, |
| 7611 | }; |
| 7612 | int status; |
| 7613 | |
| 7614 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7615 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7616 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7617 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7618 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7619 | return status; |
| 7620 | } |
| 7621 | |
| 7622 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7623 | struct rpc_cred *cred) |
| 7624 | { |
| 7625 | unsigned int loop; |
| 7626 | int ret; |
| 7627 | |
| 7628 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7629 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7630 | switch (ret) { |
| 7631 | case -NFS4ERR_DELAY: |
| 7632 | case -NFS4ERR_CLIENTID_BUSY: |
| 7633 | ssleep(1); |
| 7634 | break; |
| 7635 | default: |
| 7636 | return ret; |
| 7637 | } |
| 7638 | } |
| 7639 | return 0; |
| 7640 | } |
| 7641 | |
| 7642 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7643 | { |
| 7644 | struct rpc_cred *cred; |
| 7645 | int ret = 0; |
| 7646 | |
| 7647 | if (clp->cl_mvops->minor_version < 1) |
| 7648 | goto out; |
| 7649 | if (clp->cl_exchange_flags == 0) |
| 7650 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7651 | if (clp->cl_preserve_clid) |
| 7652 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7653 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7654 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7655 | if (cred) |
| 7656 | put_rpccred(cred); |
| 7657 | switch (ret) { |
| 7658 | case 0: |
| 7659 | case -NFS4ERR_STALE_CLIENTID: |
| 7660 | clp->cl_exchange_flags = 0; |
| 7661 | } |
| 7662 | out: |
| 7663 | return ret; |
| 7664 | } |
| 7665 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7666 | struct nfs4_get_lease_time_data { |
| 7667 | struct nfs4_get_lease_time_args *args; |
| 7668 | struct nfs4_get_lease_time_res *res; |
| 7669 | struct nfs_client *clp; |
| 7670 | }; |
| 7671 | |
| 7672 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7673 | void *calldata) |
| 7674 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7675 | struct nfs4_get_lease_time_data *data = |
| 7676 | (struct nfs4_get_lease_time_data *)calldata; |
| 7677 | |
| 7678 | dprintk("--> %s\n", __func__); |
| 7679 | /* just setup sequence, do not trigger session recovery |
| 7680 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7681 | nfs41_setup_sequence(data->clp->cl_session, |
| 7682 | &data->args->la_seq_args, |
| 7683 | &data->res->lr_seq_res, |
| 7684 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7685 | dprintk("<-- %s\n", __func__); |
| 7686 | } |
| 7687 | |
| 7688 | /* |
| 7689 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7690 | * from sequence operation or clientid errors. |
| 7691 | */ |
| 7692 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7693 | { |
| 7694 | struct nfs4_get_lease_time_data *data = |
| 7695 | (struct nfs4_get_lease_time_data *)calldata; |
| 7696 | |
| 7697 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7698 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7699 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7700 | switch (task->tk_status) { |
| 7701 | case -NFS4ERR_DELAY: |
| 7702 | case -NFS4ERR_GRACE: |
| 7703 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7704 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7705 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7706 | /* fall through */ |
| 7707 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7708 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7709 | return; |
| 7710 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7711 | dprintk("<-- %s\n", __func__); |
| 7712 | } |
| 7713 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7714 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7715 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7716 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7717 | }; |
| 7718 | |
| 7719 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7720 | { |
| 7721 | struct rpc_task *task; |
| 7722 | struct nfs4_get_lease_time_args args; |
| 7723 | struct nfs4_get_lease_time_res res = { |
| 7724 | .lr_fsinfo = fsinfo, |
| 7725 | }; |
| 7726 | struct nfs4_get_lease_time_data data = { |
| 7727 | .args = &args, |
| 7728 | .res = &res, |
| 7729 | .clp = clp, |
| 7730 | }; |
| 7731 | struct rpc_message msg = { |
| 7732 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7733 | .rpc_argp = &args, |
| 7734 | .rpc_resp = &res, |
| 7735 | }; |
| 7736 | struct rpc_task_setup task_setup = { |
| 7737 | .rpc_client = clp->cl_rpcclient, |
| 7738 | .rpc_message = &msg, |
| 7739 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7740 | .callback_data = &data, |
| 7741 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7742 | }; |
| 7743 | int status; |
| 7744 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7745 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7746 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7747 | dprintk("--> %s\n", __func__); |
| 7748 | task = rpc_run_task(&task_setup); |
| 7749 | |
| 7750 | if (IS_ERR(task)) |
| 7751 | status = PTR_ERR(task); |
| 7752 | else { |
| 7753 | status = task->tk_status; |
| 7754 | rpc_put_task(task); |
| 7755 | } |
| 7756 | dprintk("<-- %s return %d\n", __func__, status); |
| 7757 | |
| 7758 | return status; |
| 7759 | } |
| 7760 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7761 | /* |
| 7762 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7763 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7764 | * use them. |
| 7765 | * |
| 7766 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7767 | * always set csa_cachethis to FALSE because the current implementation |
| 7768 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7769 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7770 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7771 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7772 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7773 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7774 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7775 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7776 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7777 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7778 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7779 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7780 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7781 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7782 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7783 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7784 | |
| 7785 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7786 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7787 | __func__, |
| 7788 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7789 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7790 | |
| 7791 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7792 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7793 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7794 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7795 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7796 | 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] | 7797 | |
| 7798 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7799 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7800 | __func__, |
| 7801 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7802 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7803 | args->bc_attrs.max_reqs); |
| 7804 | } |
| 7805 | |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7806 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7807 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7808 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7809 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7810 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7811 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7812 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7813 | return -EINVAL; |
| 7814 | /* |
| 7815 | * Our requested max_ops is the minimum we need; we're not |
| 7816 | * prepared to break up compounds into smaller pieces than that. |
| 7817 | * So, no point even trying to continue if the server won't |
| 7818 | * cooperate: |
| 7819 | */ |
| 7820 | if (rcvd->max_ops < sent->max_ops) |
| 7821 | return -EINVAL; |
| 7822 | if (rcvd->max_reqs == 0) |
| 7823 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7824 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7825 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7826 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7827 | } |
| 7828 | |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7829 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7830 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7831 | { |
| 7832 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7833 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7834 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7835 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7836 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7837 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7838 | return -EINVAL; |
| 7839 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7840 | return -EINVAL; |
| 7841 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7842 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7843 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7844 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7845 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7846 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7847 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7848 | return 0; |
| 7849 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7850 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7851 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7852 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7853 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7854 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7855 | |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7856 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7857 | if (ret) |
| 7858 | return ret; |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7859 | return nfs4_verify_back_channel_attrs(args, res); |
| 7860 | } |
| 7861 | |
| 7862 | static void nfs4_update_session(struct nfs4_session *session, |
| 7863 | struct nfs41_create_session_res *res) |
| 7864 | { |
| 7865 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7866 | /* Mark client id and session as being confirmed */ |
| 7867 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7868 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7869 | session->flags = res->flags; |
| 7870 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7871 | if (res->flags & SESSION4_BACK_CHAN) |
| 7872 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7873 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7874 | } |
| 7875 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7876 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7877 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7878 | { |
| 7879 | struct nfs4_session *session = clp->cl_session; |
| 7880 | struct nfs41_create_session_args args = { |
| 7881 | .client = clp, |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7882 | .clientid = clp->cl_clientid, |
| 7883 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7884 | .cb_program = NFS4_CALLBACK, |
| 7885 | }; |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7886 | struct nfs41_create_session_res res; |
| 7887 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7888 | struct rpc_message msg = { |
| 7889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7890 | .rpc_argp = &args, |
| 7891 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7892 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7893 | }; |
| 7894 | int status; |
| 7895 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7896 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7897 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7898 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7899 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7900 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7901 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7902 | switch (status) { |
| 7903 | case -NFS4ERR_STALE_CLIENTID: |
| 7904 | case -NFS4ERR_DELAY: |
| 7905 | case -ETIMEDOUT: |
| 7906 | case -EACCES: |
| 7907 | case -EAGAIN: |
| 7908 | goto out; |
| 7909 | }; |
| 7910 | |
| 7911 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7912 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7913 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7914 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7915 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7916 | if (status) |
| 7917 | goto out; |
| 7918 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7919 | } |
Trond Myklebust | 79969dd1 | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7920 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7921 | return status; |
| 7922 | } |
| 7923 | |
| 7924 | /* |
| 7925 | * Issues a CREATE_SESSION operation to the server. |
| 7926 | * It is the responsibility of the caller to verify the session is |
| 7927 | * expired before calling this routine. |
| 7928 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7929 | 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] | 7930 | { |
| 7931 | int status; |
| 7932 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7933 | struct nfs4_session *session = clp->cl_session; |
| 7934 | |
| 7935 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7936 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7937 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7938 | if (status) |
| 7939 | goto out; |
| 7940 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7941 | /* Init or reset the session slot tables */ |
| 7942 | status = nfs4_setup_session_slot_tables(session); |
| 7943 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7944 | if (status) |
| 7945 | goto out; |
| 7946 | |
| 7947 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7948 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7949 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7950 | out: |
| 7951 | dprintk("<-- %s\n", __func__); |
| 7952 | return status; |
| 7953 | } |
| 7954 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7955 | /* |
| 7956 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7957 | * The caller must serialize access to this routine. |
| 7958 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7959 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7960 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7961 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7962 | struct rpc_message msg = { |
| 7963 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7964 | .rpc_argp = session, |
| 7965 | .rpc_cred = cred, |
| 7966 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7967 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7968 | |
| 7969 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7970 | |
| 7971 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7972 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7973 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7974 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7975 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7976 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7977 | |
| 7978 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7979 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7980 | "Session has been destroyed regardless...\n", status); |
| 7981 | |
| 7982 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7983 | return status; |
| 7984 | } |
| 7985 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7986 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7987 | * Renew the cl_session lease. |
| 7988 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7989 | struct nfs4_sequence_data { |
| 7990 | struct nfs_client *clp; |
| 7991 | struct nfs4_sequence_args args; |
| 7992 | struct nfs4_sequence_res res; |
| 7993 | }; |
| 7994 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7995 | static void nfs41_sequence_release(void *data) |
| 7996 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7997 | struct nfs4_sequence_data *calldata = data; |
| 7998 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7999 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8000 | if (atomic_read(&clp->cl_count) > 1) |
| 8001 | nfs4_schedule_state_renewal(clp); |
| 8002 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8003 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8004 | } |
| 8005 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8006 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8007 | { |
| 8008 | switch(task->tk_status) { |
| 8009 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8010 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8011 | return -EAGAIN; |
| 8012 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8013 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8014 | } |
| 8015 | return 0; |
| 8016 | } |
| 8017 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8018 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8019 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8020 | struct nfs4_sequence_data *calldata = data; |
| 8021 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8022 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8023 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8024 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8025 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8026 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8027 | if (task->tk_status < 0) { |
| 8028 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8029 | if (atomic_read(&clp->cl_count) == 1) |
| 8030 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8031 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8032 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8033 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8034 | return; |
| 8035 | } |
| 8036 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8037 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8038 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8039 | dprintk("<-- %s\n", __func__); |
| 8040 | } |
| 8041 | |
| 8042 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8043 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8044 | struct nfs4_sequence_data *calldata = data; |
| 8045 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8046 | struct nfs4_sequence_args *args; |
| 8047 | struct nfs4_sequence_res *res; |
| 8048 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8049 | args = task->tk_msg.rpc_argp; |
| 8050 | res = task->tk_msg.rpc_resp; |
| 8051 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8052 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8053 | } |
| 8054 | |
| 8055 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8056 | .rpc_call_done = nfs41_sequence_call_done, |
| 8057 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8058 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8059 | }; |
| 8060 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8061 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8062 | struct rpc_cred *cred, |
| 8063 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8064 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8065 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8066 | struct rpc_message msg = { |
| 8067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8068 | .rpc_cred = cred, |
| 8069 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8070 | struct rpc_task_setup task_setup_data = { |
| 8071 | .rpc_client = clp->cl_rpcclient, |
| 8072 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8073 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8074 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8075 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8076 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8077 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8078 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8079 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8080 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8081 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8082 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8083 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8084 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8085 | if (is_privileged) |
| 8086 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8087 | msg.rpc_argp = &calldata->args; |
| 8088 | msg.rpc_resp = &calldata->res; |
| 8089 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8090 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8091 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8092 | return rpc_run_task(&task_setup_data); |
| 8093 | } |
| 8094 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8095 | 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] | 8096 | { |
| 8097 | struct rpc_task *task; |
| 8098 | int ret = 0; |
| 8099 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8100 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8101 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8102 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8103 | if (IS_ERR(task)) |
| 8104 | ret = PTR_ERR(task); |
| 8105 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8106 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8107 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8108 | return ret; |
| 8109 | } |
| 8110 | |
| 8111 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8112 | { |
| 8113 | struct rpc_task *task; |
| 8114 | int ret; |
| 8115 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8116 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8117 | if (IS_ERR(task)) { |
| 8118 | ret = PTR_ERR(task); |
| 8119 | goto out; |
| 8120 | } |
| 8121 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8122 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8123 | ret = task->tk_status; |
| 8124 | rpc_put_task(task); |
| 8125 | out: |
| 8126 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8127 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8128 | } |
| 8129 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8130 | struct nfs4_reclaim_complete_data { |
| 8131 | struct nfs_client *clp; |
| 8132 | struct nfs41_reclaim_complete_args arg; |
| 8133 | struct nfs41_reclaim_complete_res res; |
| 8134 | }; |
| 8135 | |
| 8136 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8137 | { |
| 8138 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8139 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8140 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8141 | &calldata->arg.seq_args, |
| 8142 | &calldata->res.seq_res, |
| 8143 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8144 | } |
| 8145 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8146 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8147 | { |
| 8148 | switch(task->tk_status) { |
| 8149 | case 0: |
| 8150 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8151 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8152 | break; |
| 8153 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8154 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8155 | /* fall through */ |
| 8156 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8157 | return -EAGAIN; |
| 8158 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8159 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8160 | } |
| 8161 | return 0; |
| 8162 | } |
| 8163 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8164 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8165 | { |
| 8166 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8167 | struct nfs_client *clp = calldata->clp; |
| 8168 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8169 | |
| 8170 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8171 | if (!nfs41_sequence_done(task, res)) |
| 8172 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8173 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8174 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8175 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8176 | rpc_restart_call_prepare(task); |
| 8177 | return; |
| 8178 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8179 | dprintk("<-- %s\n", __func__); |
| 8180 | } |
| 8181 | |
| 8182 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8183 | { |
| 8184 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8185 | |
| 8186 | kfree(calldata); |
| 8187 | } |
| 8188 | |
| 8189 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8190 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8191 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8192 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8193 | }; |
| 8194 | |
| 8195 | /* |
| 8196 | * Issue a global reclaim complete. |
| 8197 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8198 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8199 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8200 | { |
| 8201 | struct nfs4_reclaim_complete_data *calldata; |
| 8202 | struct rpc_task *task; |
| 8203 | struct rpc_message msg = { |
| 8204 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8205 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8206 | }; |
| 8207 | struct rpc_task_setup task_setup_data = { |
| 8208 | .rpc_client = clp->cl_rpcclient, |
| 8209 | .rpc_message = &msg, |
| 8210 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8211 | .flags = RPC_TASK_ASYNC, |
| 8212 | }; |
| 8213 | int status = -ENOMEM; |
| 8214 | |
| 8215 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8216 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8217 | if (calldata == NULL) |
| 8218 | goto out; |
| 8219 | calldata->clp = clp; |
| 8220 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8221 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8222 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8223 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8224 | msg.rpc_argp = &calldata->arg; |
| 8225 | msg.rpc_resp = &calldata->res; |
| 8226 | task_setup_data.callback_data = calldata; |
| 8227 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8228 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8229 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8230 | goto out; |
| 8231 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8232 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8233 | if (status == 0) |
| 8234 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8235 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8236 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8237 | out: |
| 8238 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8239 | return status; |
| 8240 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8241 | |
| 8242 | static void |
| 8243 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8244 | { |
| 8245 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8246 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8247 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8248 | |
| 8249 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8250 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8251 | &lgp->res.seq_res, task); |
| 8252 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8253 | } |
| 8254 | |
| 8255 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8256 | { |
| 8257 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8258 | |
| 8259 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8260 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8261 | dprintk("<-- %s\n", __func__); |
| 8262 | } |
| 8263 | |
| 8264 | static int |
| 8265 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8266 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8267 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8268 | struct inode *inode = lgp->args.inode; |
| 8269 | struct nfs_server *server = NFS_SERVER(inode); |
| 8270 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8271 | int nfs4err = task->tk_status; |
| 8272 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8273 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8274 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8275 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8276 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8277 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8278 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8279 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8280 | |
| 8281 | /* |
| 8282 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8283 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8284 | * retry go inband. |
| 8285 | */ |
| 8286 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8287 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8288 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8289 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8290 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8291 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8292 | */ |
| 8293 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8294 | status = -EOVERFLOW; |
| 8295 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8296 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8297 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8298 | * (or clients) writing to the same RAID stripe except when |
| 8299 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8300 | * |
| 8301 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8302 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8303 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8304 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8305 | if (lgp->args.minlength == 0) { |
| 8306 | status = -EOVERFLOW; |
| 8307 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8308 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8309 | status = -EBUSY; |
| 8310 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8311 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8312 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8313 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8314 | case -NFS4ERR_DELEG_REVOKED: |
| 8315 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8316 | case -NFS4ERR_EXPIRED: |
| 8317 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8318 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8319 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8320 | lo = NFS_I(inode)->layout; |
| 8321 | /* If the open stateid was bad, then recover it. */ |
| 8322 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8323 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8324 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8325 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8326 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8327 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8328 | break; |
| 8329 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8330 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8331 | /* |
| 8332 | * Mark the bad layout state as invalid, then retry |
| 8333 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8334 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8335 | spin_unlock(&inode->i_lock); |
| 8336 | pnfs_free_lseg_list(&head); |
| 8337 | status = -EAGAIN; |
| 8338 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8339 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8340 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8341 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8342 | if (!status) { |
| 8343 | if (exception->retry) |
| 8344 | status = -EAGAIN; |
| 8345 | else |
| 8346 | status = err; |
| 8347 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8348 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8349 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8350 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8351 | } |
| 8352 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8353 | static size_t max_response_pages(struct nfs_server *server) |
| 8354 | { |
| 8355 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8356 | return nfs_page_array_len(0, max_resp_sz); |
| 8357 | } |
| 8358 | |
| 8359 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8360 | { |
| 8361 | int i; |
| 8362 | |
| 8363 | if (!pages) |
| 8364 | return; |
| 8365 | |
| 8366 | for (i = 0; i < size; i++) { |
| 8367 | if (!pages[i]) |
| 8368 | break; |
| 8369 | __free_page(pages[i]); |
| 8370 | } |
| 8371 | kfree(pages); |
| 8372 | } |
| 8373 | |
| 8374 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8375 | { |
| 8376 | struct page **pages; |
| 8377 | int i; |
| 8378 | |
| 8379 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8380 | if (!pages) { |
| 8381 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8382 | return NULL; |
| 8383 | } |
| 8384 | |
| 8385 | for (i = 0; i < size; i++) { |
| 8386 | pages[i] = alloc_page(gfp_flags); |
| 8387 | if (!pages[i]) { |
| 8388 | dprintk("%s: failed to allocate page\n", __func__); |
| 8389 | nfs4_free_pages(pages, size); |
| 8390 | return NULL; |
| 8391 | } |
| 8392 | } |
| 8393 | |
| 8394 | return pages; |
| 8395 | } |
| 8396 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8397 | static void nfs4_layoutget_release(void *calldata) |
| 8398 | { |
| 8399 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8400 | struct inode *inode = lgp->args.inode; |
| 8401 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8402 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8403 | |
| 8404 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8405 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8406 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8407 | put_nfs_open_context(lgp->args.ctx); |
| 8408 | kfree(calldata); |
| 8409 | dprintk("<-- %s\n", __func__); |
| 8410 | } |
| 8411 | |
| 8412 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8413 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8414 | .rpc_call_done = nfs4_layoutget_done, |
| 8415 | .rpc_release = nfs4_layoutget_release, |
| 8416 | }; |
| 8417 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8418 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8419 | 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] | 8420 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8421 | struct inode *inode = lgp->args.inode; |
| 8422 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8423 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8424 | struct rpc_task *task; |
| 8425 | struct rpc_message msg = { |
| 8426 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8427 | .rpc_argp = &lgp->args, |
| 8428 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8429 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8430 | }; |
| 8431 | struct rpc_task_setup task_setup_data = { |
| 8432 | .rpc_client = server->client, |
| 8433 | .rpc_message = &msg, |
| 8434 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8435 | .callback_data = lgp, |
| 8436 | .flags = RPC_TASK_ASYNC, |
| 8437 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8438 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8439 | struct nfs4_exception exception = { |
| 8440 | .inode = inode, |
| 8441 | .timeout = *timeout, |
| 8442 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8443 | int status = 0; |
| 8444 | |
| 8445 | dprintk("--> %s\n", __func__); |
| 8446 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8447 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8448 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8449 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8450 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8451 | if (!lgp->args.layout.pages) { |
| 8452 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8453 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8454 | } |
| 8455 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8456 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8457 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8458 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8459 | 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] | 8460 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8461 | task = rpc_run_task(&task_setup_data); |
| 8462 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8463 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8464 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8465 | if (status == 0) { |
| 8466 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8467 | *timeout = exception.timeout; |
| 8468 | } |
| 8469 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8470 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8471 | &lgp->args.range, |
| 8472 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8473 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8474 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8475 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8476 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8477 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8478 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8479 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8480 | rpc_put_task(task); |
| 8481 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8482 | if (status) |
| 8483 | return ERR_PTR(status); |
| 8484 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8485 | } |
| 8486 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8487 | static void |
| 8488 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8489 | { |
| 8490 | struct nfs4_layoutreturn *lrp = calldata; |
| 8491 | |
| 8492 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8493 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8494 | &lrp->args.seq_args, |
| 8495 | &lrp->res.seq_res, |
| 8496 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8497 | } |
| 8498 | |
| 8499 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8500 | { |
| 8501 | struct nfs4_layoutreturn *lrp = calldata; |
| 8502 | struct nfs_server *server; |
| 8503 | |
| 8504 | dprintk("--> %s\n", __func__); |
| 8505 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8506 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8507 | return; |
| 8508 | |
| 8509 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8510 | switch (task->tk_status) { |
| 8511 | default: |
| 8512 | task->tk_status = 0; |
| 8513 | case 0: |
| 8514 | break; |
| 8515 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8516 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8517 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8518 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8519 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8520 | return; |
| 8521 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8522 | dprintk("<-- %s\n", __func__); |
| 8523 | } |
| 8524 | |
| 8525 | static void nfs4_layoutreturn_release(void *calldata) |
| 8526 | { |
| 8527 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8528 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8529 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8530 | |
| 8531 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8532 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8533 | if (lrp->res.lrs_present) { |
| 8534 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8535 | &lrp->args.range, |
| 8536 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8537 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8538 | } else |
| 8539 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8540 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8541 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8542 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8543 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8544 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8545 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8546 | kfree(calldata); |
| 8547 | dprintk("<-- %s\n", __func__); |
| 8548 | } |
| 8549 | |
| 8550 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8551 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8552 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8553 | .rpc_release = nfs4_layoutreturn_release, |
| 8554 | }; |
| 8555 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8556 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8557 | { |
| 8558 | struct rpc_task *task; |
| 8559 | struct rpc_message msg = { |
| 8560 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8561 | .rpc_argp = &lrp->args, |
| 8562 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8563 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8564 | }; |
| 8565 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c577 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8566 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8567 | .rpc_message = &msg, |
| 8568 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8569 | .callback_data = lrp, |
| 8570 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8571 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8572 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8573 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8574 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8575 | &task_setup_data.rpc_client, &msg); |
| 8576 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8577 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8578 | if (!sync) { |
| 8579 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8580 | if (!lrp->inode) { |
| 8581 | nfs4_layoutreturn_release(lrp); |
| 8582 | return -EAGAIN; |
| 8583 | } |
| 8584 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8585 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8586 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8587 | task = rpc_run_task(&task_setup_data); |
| 8588 | if (IS_ERR(task)) |
| 8589 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8590 | if (sync) |
| 8591 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8592 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8593 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8594 | rpc_put_task(task); |
| 8595 | return status; |
| 8596 | } |
| 8597 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8598 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8599 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8600 | struct pnfs_device *pdev, |
| 8601 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8602 | { |
| 8603 | struct nfs4_getdeviceinfo_args args = { |
| 8604 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8605 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8606 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8607 | }; |
| 8608 | struct nfs4_getdeviceinfo_res res = { |
| 8609 | .pdev = pdev, |
| 8610 | }; |
| 8611 | struct rpc_message msg = { |
| 8612 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8613 | .rpc_argp = &args, |
| 8614 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8615 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8616 | }; |
| 8617 | int status; |
| 8618 | |
| 8619 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8620 | 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] | 8621 | if (res.notification & ~args.notify_types) |
| 8622 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8623 | if (res.notification != args.notify_types) |
| 8624 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8625 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8626 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8627 | |
| 8628 | return status; |
| 8629 | } |
| 8630 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8631 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8632 | struct pnfs_device *pdev, |
| 8633 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8634 | { |
| 8635 | struct nfs4_exception exception = { }; |
| 8636 | int err; |
| 8637 | |
| 8638 | do { |
| 8639 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8640 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8641 | &exception); |
| 8642 | } while (exception.retry); |
| 8643 | return err; |
| 8644 | } |
| 8645 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8646 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8647 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8648 | { |
| 8649 | struct nfs4_layoutcommit_data *data = calldata; |
| 8650 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8651 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8652 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8653 | nfs41_setup_sequence(session, |
| 8654 | &data->args.seq_args, |
| 8655 | &data->res.seq_res, |
| 8656 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | static void |
| 8660 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8661 | { |
| 8662 | struct nfs4_layoutcommit_data *data = calldata; |
| 8663 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8664 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8665 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8666 | return; |
| 8667 | |
| 8668 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8669 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8670 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8671 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8672 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8673 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8674 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8675 | break; |
| 8676 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8677 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8678 | rpc_restart_call_prepare(task); |
| 8679 | return; |
| 8680 | } |
| 8681 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8682 | } |
| 8683 | |
| 8684 | static void nfs4_layoutcommit_release(void *calldata) |
| 8685 | { |
| 8686 | struct nfs4_layoutcommit_data *data = calldata; |
| 8687 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8688 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8689 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8690 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8691 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8692 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8693 | kfree(data); |
| 8694 | } |
| 8695 | |
| 8696 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8697 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8698 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8699 | .rpc_release = nfs4_layoutcommit_release, |
| 8700 | }; |
| 8701 | |
| 8702 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8703 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8704 | { |
| 8705 | struct rpc_message msg = { |
| 8706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8707 | .rpc_argp = &data->args, |
| 8708 | .rpc_resp = &data->res, |
| 8709 | .rpc_cred = data->cred, |
| 8710 | }; |
| 8711 | struct rpc_task_setup task_setup_data = { |
| 8712 | .task = &data->task, |
| 8713 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8714 | .rpc_message = &msg, |
| 8715 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8716 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8717 | }; |
| 8718 | struct rpc_task *task; |
| 8719 | int status = 0; |
| 8720 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8721 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8722 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8723 | data->args.lastbytewritten, |
| 8724 | data->args.inode->i_ino); |
| 8725 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8726 | if (!sync) { |
| 8727 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8728 | if (data->inode == NULL) { |
| 8729 | nfs4_layoutcommit_release(data); |
| 8730 | return -EAGAIN; |
| 8731 | } |
| 8732 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8733 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8734 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8735 | task = rpc_run_task(&task_setup_data); |
| 8736 | if (IS_ERR(task)) |
| 8737 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8738 | if (sync) |
| 8739 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8740 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8741 | dprintk("%s: status %d\n", __func__, status); |
| 8742 | rpc_put_task(task); |
| 8743 | return status; |
| 8744 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8745 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8746 | /** |
| 8747 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8748 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8749 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8750 | static int |
| 8751 | _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] | 8752 | struct nfs_fsinfo *info, |
| 8753 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8754 | { |
| 8755 | struct nfs41_secinfo_no_name_args args = { |
| 8756 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8757 | }; |
| 8758 | struct nfs4_secinfo_res res = { |
| 8759 | .flavors = flavors, |
| 8760 | }; |
| 8761 | struct rpc_message msg = { |
| 8762 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8763 | .rpc_argp = &args, |
| 8764 | .rpc_resp = &res, |
| 8765 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8766 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8767 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8768 | int status; |
| 8769 | |
| 8770 | if (use_integrity) { |
| 8771 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8772 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8773 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | dprintk("--> %s\n", __func__); |
| 8777 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8778 | &res.seq_res, 0); |
| 8779 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8780 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8781 | if (cred) |
| 8782 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8783 | |
| 8784 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8785 | } |
| 8786 | |
| 8787 | static int |
| 8788 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8789 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8790 | { |
| 8791 | struct nfs4_exception exception = { }; |
| 8792 | int err; |
| 8793 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8794 | /* first try using integrity protection */ |
| 8795 | err = -NFS4ERR_WRONGSEC; |
| 8796 | |
| 8797 | /* try to use integrity protection with machine cred */ |
| 8798 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8799 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8800 | flavors, true); |
| 8801 | |
| 8802 | /* |
| 8803 | * if unable to use integrity protection, or SECINFO with |
| 8804 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8805 | * disallowed by spec, but exists in deployed servers) use |
| 8806 | * the current filesystem's rpc_client and the user cred. |
| 8807 | */ |
| 8808 | if (err == -NFS4ERR_WRONGSEC) |
| 8809 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8810 | flavors, false); |
| 8811 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8812 | switch (err) { |
| 8813 | case 0: |
| 8814 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8815 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8816 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8817 | default: |
| 8818 | err = nfs4_handle_exception(server, err, &exception); |
| 8819 | } |
| 8820 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8821 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8822 | return err; |
| 8823 | } |
| 8824 | |
| 8825 | static int |
| 8826 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8827 | struct nfs_fsinfo *info) |
| 8828 | { |
| 8829 | int err; |
| 8830 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8831 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8832 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8833 | struct nfs4_secinfo4 *secinfo; |
| 8834 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8835 | |
| 8836 | page = alloc_page(GFP_KERNEL); |
| 8837 | if (!page) { |
| 8838 | err = -ENOMEM; |
| 8839 | goto out; |
| 8840 | } |
| 8841 | |
| 8842 | flavors = page_address(page); |
| 8843 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8844 | |
| 8845 | /* |
| 8846 | * Fall back on "guess and check" method if |
| 8847 | * the server doesn't support SECINFO_NO_NAME |
| 8848 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8849 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8850 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8851 | goto out_freepage; |
| 8852 | } |
| 8853 | if (err) |
| 8854 | goto out_freepage; |
| 8855 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8856 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8857 | secinfo = &flavors->flavors[i]; |
| 8858 | |
| 8859 | switch (secinfo->flavor) { |
| 8860 | case RPC_AUTH_NULL: |
| 8861 | case RPC_AUTH_UNIX: |
| 8862 | case RPC_AUTH_GSS: |
| 8863 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8864 | &secinfo->flavor_info); |
| 8865 | break; |
| 8866 | default: |
| 8867 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8868 | break; |
| 8869 | } |
| 8870 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8871 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8872 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8873 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8874 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8875 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8876 | info, flavor); |
| 8877 | if (!err) |
| 8878 | break; |
| 8879 | } |
| 8880 | } |
| 8881 | |
| 8882 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8883 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8884 | |
| 8885 | out_freepage: |
| 8886 | put_page(page); |
| 8887 | if (err == -EACCES) |
| 8888 | return -EPERM; |
| 8889 | out: |
| 8890 | return err; |
| 8891 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8892 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8893 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8894 | nfs4_stateid *stateid, |
| 8895 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8896 | { |
| 8897 | int status; |
| 8898 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8899 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8900 | }; |
| 8901 | struct nfs41_test_stateid_res res; |
| 8902 | struct rpc_message msg = { |
| 8903 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8904 | .rpc_argp = &args, |
| 8905 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8906 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8907 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8908 | struct rpc_clnt *rpc_client = server->client; |
| 8909 | |
| 8910 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8911 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8912 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8913 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8914 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8915 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8916 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8917 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8918 | if (status != NFS_OK) { |
| 8919 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8920 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8921 | } |
| 8922 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8923 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8924 | } |
| 8925 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8926 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8927 | int err, struct nfs4_exception *exception) |
| 8928 | { |
| 8929 | exception->retry = 0; |
| 8930 | switch(err) { |
| 8931 | case -NFS4ERR_DELAY: |
| 8932 | nfs4_handle_exception(server, err, exception); |
| 8933 | break; |
| 8934 | case -NFS4ERR_BADSESSION: |
| 8935 | case -NFS4ERR_BADSLOT: |
| 8936 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8937 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8938 | case -NFS4ERR_DEADSESSION: |
| 8939 | nfs4_do_handle_exception(server, err, exception); |
| 8940 | } |
| 8941 | } |
| 8942 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8943 | /** |
| 8944 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8945 | * |
| 8946 | * @server: server / transport on which to perform the operation |
| 8947 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8948 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8949 | * |
| 8950 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8951 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8952 | * failed or the state ID is not currently valid. |
| 8953 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8954 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8955 | nfs4_stateid *stateid, |
| 8956 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8957 | { |
| 8958 | struct nfs4_exception exception = { }; |
| 8959 | int err; |
| 8960 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8961 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8962 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8963 | } while (exception.retry); |
| 8964 | return err; |
| 8965 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8966 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8967 | struct nfs_free_stateid_data { |
| 8968 | struct nfs_server *server; |
| 8969 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8970 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8971 | }; |
| 8972 | |
| 8973 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8974 | { |
| 8975 | struct nfs_free_stateid_data *data = calldata; |
| 8976 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8977 | &data->args.seq_args, |
| 8978 | &data->res.seq_res, |
| 8979 | task); |
| 8980 | } |
| 8981 | |
| 8982 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8983 | { |
| 8984 | struct nfs_free_stateid_data *data = calldata; |
| 8985 | |
| 8986 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8987 | |
| 8988 | switch (task->tk_status) { |
| 8989 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8990 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8991 | rpc_restart_call_prepare(task); |
| 8992 | } |
| 8993 | } |
| 8994 | |
| 8995 | static void nfs41_free_stateid_release(void *calldata) |
| 8996 | { |
| 8997 | kfree(calldata); |
| 8998 | } |
| 8999 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9000 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9001 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9002 | .rpc_call_done = nfs41_free_stateid_done, |
| 9003 | .rpc_release = nfs41_free_stateid_release, |
| 9004 | }; |
| 9005 | |
| 9006 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9007 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9008 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9009 | bool privileged) |
| 9010 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9011 | struct rpc_message msg = { |
| 9012 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9013 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9014 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9015 | struct rpc_task_setup task_setup = { |
| 9016 | .rpc_client = server->client, |
| 9017 | .rpc_message = &msg, |
| 9018 | .callback_ops = &nfs41_free_stateid_ops, |
| 9019 | .flags = RPC_TASK_ASYNC, |
| 9020 | }; |
| 9021 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9022 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9023 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9024 | &task_setup.rpc_client, &msg); |
| 9025 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9026 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9027 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9028 | if (!data) |
| 9029 | return ERR_PTR(-ENOMEM); |
| 9030 | data->server = server; |
| 9031 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9032 | |
| 9033 | task_setup.callback_data = data; |
| 9034 | |
| 9035 | msg.rpc_argp = &data->args; |
| 9036 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9037 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9038 | if (privileged) |
| 9039 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9040 | |
| 9041 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9042 | } |
| 9043 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9044 | /** |
| 9045 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9046 | * |
| 9047 | * @server: server / transport on which to perform the operation |
| 9048 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9049 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9050 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9051 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9052 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9053 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9054 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9055 | const nfs4_stateid *stateid, |
| 9056 | struct rpc_cred *cred, |
| 9057 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9058 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9059 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9060 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9061 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9062 | if (IS_ERR(task)) |
| 9063 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9064 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9065 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9066 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9067 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9068 | static void |
| 9069 | 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] | 9070 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9071 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9072 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9073 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9074 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9075 | } |
| 9076 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9077 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9078 | const nfs4_stateid *s2) |
| 9079 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9080 | if (s1->type != s2->type) |
| 9081 | return false; |
| 9082 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9083 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9084 | return false; |
| 9085 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9086 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9087 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9088 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9089 | return true; |
| 9090 | |
| 9091 | return false; |
| 9092 | } |
| 9093 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9094 | #endif /* CONFIG_NFS_V4_1 */ |
| 9095 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9096 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9097 | const nfs4_stateid *s2) |
| 9098 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9099 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9100 | } |
| 9101 | |
| 9102 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9103 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9104 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9105 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9106 | .recover_open = nfs4_open_reclaim, |
| 9107 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9108 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9109 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9110 | }; |
| 9111 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9112 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9113 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9114 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9115 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9116 | .recover_open = nfs4_open_reclaim, |
| 9117 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9118 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9119 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9120 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9121 | }; |
| 9122 | #endif /* CONFIG_NFS_V4_1 */ |
| 9123 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9124 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9125 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9126 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9127 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9128 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9129 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9130 | }; |
| 9131 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9132 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9133 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9134 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9135 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9136 | .recover_open = nfs41_open_expired, |
| 9137 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9138 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9139 | }; |
| 9140 | #endif /* CONFIG_NFS_V4_1 */ |
| 9141 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9142 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9143 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9144 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9145 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9146 | }; |
| 9147 | |
| 9148 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9149 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9150 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9151 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9152 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9153 | }; |
| 9154 | #endif |
| 9155 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9156 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9157 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9158 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9159 | }; |
| 9160 | |
| 9161 | #if defined(CONFIG_NFS_V4_1) |
| 9162 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9163 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9164 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9165 | }; |
| 9166 | #endif /* CONFIG_NFS_V4_1 */ |
| 9167 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9168 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9169 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9170 | .init_caps = NFS_CAP_READDIRPLUS |
| 9171 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9172 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9173 | .init_client = nfs40_init_client, |
| 9174 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9175 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9176 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9177 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9178 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9179 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9180 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9181 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9182 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9183 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9184 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9185 | }; |
| 9186 | |
| 9187 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9188 | static struct nfs_seqid * |
| 9189 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9190 | { |
| 9191 | return NULL; |
| 9192 | } |
| 9193 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9194 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9195 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9196 | .init_caps = NFS_CAP_READDIRPLUS |
| 9197 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9198 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9199 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9200 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9201 | .init_client = nfs41_init_client, |
| 9202 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9203 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9204 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9205 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9206 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9207 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9208 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9209 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9210 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9211 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9212 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9213 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9214 | }; |
| 9215 | #endif |
| 9216 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9217 | #if defined(CONFIG_NFS_V4_2) |
| 9218 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9219 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9220 | .init_caps = NFS_CAP_READDIRPLUS |
| 9221 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9222 | | NFS_CAP_POSIX_LOCK |
| 9223 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9224 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9225 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9226 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9227 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9228 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9229 | | NFS_CAP_LAYOUTSTATS |
| 9230 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9231 | .init_client = nfs41_init_client, |
| 9232 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9233 | .match_stateid = nfs41_match_stateid, |
| 9234 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9235 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9236 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9237 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9238 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9239 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9240 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9241 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9242 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9243 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9244 | }; |
| 9245 | #endif |
| 9246 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9247 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9248 | [0] = &nfs_v4_0_minor_ops, |
| 9249 | #if defined(CONFIG_NFS_V4_1) |
| 9250 | [1] = &nfs_v4_1_minor_ops, |
| 9251 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9252 | #if defined(CONFIG_NFS_V4_2) |
| 9253 | [2] = &nfs_v4_2_minor_ops, |
| 9254 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9255 | }; |
| 9256 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9257 | 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] | 9258 | { |
| 9259 | ssize_t error, error2; |
| 9260 | |
| 9261 | error = generic_listxattr(dentry, list, size); |
| 9262 | if (error < 0) |
| 9263 | return error; |
| 9264 | if (list) { |
| 9265 | list += error; |
| 9266 | size -= error; |
| 9267 | } |
| 9268 | |
| 9269 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9270 | if (error2 < 0) |
| 9271 | return error2; |
| 9272 | return error + error2; |
| 9273 | } |
| 9274 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9275 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9276 | .create = nfs_create, |
| 9277 | .lookup = nfs_lookup, |
| 9278 | .atomic_open = nfs_atomic_open, |
| 9279 | .link = nfs_link, |
| 9280 | .unlink = nfs_unlink, |
| 9281 | .symlink = nfs_symlink, |
| 9282 | .mkdir = nfs_mkdir, |
| 9283 | .rmdir = nfs_rmdir, |
| 9284 | .mknod = nfs_mknod, |
| 9285 | .rename = nfs_rename, |
| 9286 | .permission = nfs_permission, |
| 9287 | .getattr = nfs_getattr, |
| 9288 | .setattr = nfs_setattr, |
| 9289 | .getxattr = generic_getxattr, |
| 9290 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9291 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9292 | .removexattr = generic_removexattr, |
| 9293 | }; |
| 9294 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9295 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9296 | .permission = nfs_permission, |
| 9297 | .getattr = nfs_getattr, |
| 9298 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9299 | .getxattr = generic_getxattr, |
| 9300 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9301 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9302 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9303 | }; |
| 9304 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9305 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9306 | .version = 4, /* protocol version */ |
| 9307 | .dentry_ops = &nfs4_dentry_operations, |
| 9308 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9309 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9310 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9311 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9312 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9313 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9314 | .getattr = nfs4_proc_getattr, |
| 9315 | .setattr = nfs4_proc_setattr, |
| 9316 | .lookup = nfs4_proc_lookup, |
| 9317 | .access = nfs4_proc_access, |
| 9318 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9319 | .create = nfs4_proc_create, |
| 9320 | .remove = nfs4_proc_remove, |
| 9321 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9322 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9323 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9324 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9325 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9326 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9327 | .link = nfs4_proc_link, |
| 9328 | .symlink = nfs4_proc_symlink, |
| 9329 | .mkdir = nfs4_proc_mkdir, |
| 9330 | .rmdir = nfs4_proc_remove, |
| 9331 | .readdir = nfs4_proc_readdir, |
| 9332 | .mknod = nfs4_proc_mknod, |
| 9333 | .statfs = nfs4_proc_statfs, |
| 9334 | .fsinfo = nfs4_proc_fsinfo, |
| 9335 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9336 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9337 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9338 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9339 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9340 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9341 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9342 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9343 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9344 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9345 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9346 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9347 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9348 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9349 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9350 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9351 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9352 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9353 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9354 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9355 | .create_server = nfs4_create_server, |
| 9356 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9357 | }; |
| 9358 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9359 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9360 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9361 | .list = nfs4_xattr_list_nfs4_acl, |
| 9362 | .get = nfs4_xattr_get_nfs4_acl, |
| 9363 | .set = nfs4_xattr_set_nfs4_acl, |
| 9364 | }; |
| 9365 | |
| 9366 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9367 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9368 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9369 | &nfs4_xattr_nfs4_label_handler, |
| 9370 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9371 | NULL |
| 9372 | }; |
| 9373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9374 | /* |
| 9375 | * Local variables: |
| 9376 | * c-basic-offset: 8 |
| 9377 | * End: |
| 9378 | */ |