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 *); |
| 102 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 103 | struct rpc_cred *); |
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 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 331 | static long nfs4_update_delay(long *timeout) |
| 332 | { |
| 333 | long ret; |
| 334 | if (!timeout) |
| 335 | return NFS4_POLL_RETRY_MAX; |
| 336 | if (*timeout <= 0) |
| 337 | *timeout = NFS4_POLL_RETRY_MIN; |
| 338 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 339 | *timeout = NFS4_POLL_RETRY_MAX; |
| 340 | ret = *timeout; |
| 341 | *timeout <<= 1; |
| 342 | return ret; |
| 343 | } |
| 344 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 346 | { |
| 347 | int res = 0; |
| 348 | |
| 349 | might_sleep(); |
| 350 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 351 | freezable_schedule_timeout_killable_unsafe( |
| 352 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | if (fatal_signal_pending(current)) |
| 354 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | return res; |
| 356 | } |
| 357 | |
| 358 | /* This is the error handling routine for processes that are allowed |
| 359 | * to sleep. |
| 360 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 361 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 362 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | { |
| 364 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 365 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 366 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 367 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 368 | int ret = errorcode; |
| 369 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 370 | exception->delay = 0; |
| 371 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | exception->retry = 0; |
| 373 | switch(errorcode) { |
| 374 | case 0: |
| 375 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 376 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_DELEG_REVOKED: |
| 378 | case -NFS4ERR_ADMIN_REVOKED: |
| 379 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 380 | if (inode) { |
| 381 | int err; |
| 382 | |
| 383 | err = nfs_async_inode_return_delegation(inode, |
| 384 | stateid); |
| 385 | if (err == 0) |
| 386 | goto wait_on_recovery; |
| 387 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 388 | exception->retry = 1; |
| 389 | break; |
| 390 | } |
| 391 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | if (state == NULL) |
| 393 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 394 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 395 | if (ret < 0) |
| 396 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 398 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 399 | if (state != NULL) { |
| 400 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 401 | if (ret < 0) |
| 402 | break; |
| 403 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 405 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 406 | nfs4_schedule_lease_recovery(clp); |
| 407 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 408 | case -NFS4ERR_MOVED: |
| 409 | ret = nfs4_schedule_migration_recovery(server); |
| 410 | if (ret < 0) |
| 411 | break; |
| 412 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 413 | case -NFS4ERR_LEASE_MOVED: |
| 414 | nfs4_schedule_lease_moved_recovery(clp); |
| 415 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 416 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 417 | case -NFS4ERR_BADSESSION: |
| 418 | case -NFS4ERR_BADSLOT: |
| 419 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 420 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 421 | case -NFS4ERR_DEADSESSION: |
| 422 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 423 | case -NFS4ERR_SEQ_MISORDERED: |
| 424 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 425 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 426 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 427 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 428 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 430 | if (exception->timeout > HZ) { |
| 431 | /* We have retried a decent amount, time to |
| 432 | * fail |
| 433 | */ |
| 434 | ret = -EBUSY; |
| 435 | break; |
| 436 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 438 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 439 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 440 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 441 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 442 | exception->delay = 1; |
| 443 | return 0; |
| 444 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 445 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 446 | case -NFS4ERR_OLD_STATEID: |
| 447 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 448 | break; |
| 449 | case -NFS4ERR_BADOWNER: |
| 450 | /* The following works around a Linux server bug! */ |
| 451 | case -NFS4ERR_BADNAME: |
| 452 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 453 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 454 | exception->retry = 1; |
| 455 | printk(KERN_WARNING "NFS: v4 server %s " |
| 456 | "does not accept raw " |
| 457 | "uid/gids. " |
| 458 | "Reenabling the idmapper.\n", |
| 459 | server->nfs_client->cl_hostname); |
| 460 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | } |
| 462 | /* We failed to handle the error */ |
| 463 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 464 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 465 | exception->recovering = 1; |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /* This is the error handling routine for processes that are allowed |
| 470 | * to sleep. |
| 471 | */ |
| 472 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 473 | { |
| 474 | struct nfs_client *clp = server->nfs_client; |
| 475 | int ret; |
| 476 | |
| 477 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 478 | if (exception->delay) { |
| 479 | ret = nfs4_delay(server->client, &exception->timeout); |
| 480 | goto out_retry; |
| 481 | } |
| 482 | if (exception->recovering) { |
| 483 | ret = nfs4_wait_clnt_recover(clp); |
| 484 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 485 | return -EIO; |
| 486 | goto out_retry; |
| 487 | } |
| 488 | return ret; |
| 489 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 490 | if (ret == 0) |
| 491 | exception->retry = 1; |
| 492 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 495 | static int |
| 496 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 497 | int errorcode, struct nfs4_exception *exception) |
| 498 | { |
| 499 | struct nfs_client *clp = server->nfs_client; |
| 500 | int ret; |
| 501 | |
| 502 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 503 | if (exception->delay) { |
| 504 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 505 | goto out_retry; |
| 506 | } |
| 507 | if (exception->recovering) { |
| 508 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 509 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 510 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 511 | goto out_retry; |
| 512 | } |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | ret = -EIO; |
| 515 | return ret; |
| 516 | out_retry: |
| 517 | if (ret == 0) |
| 518 | exception->retry = 1; |
| 519 | return ret; |
| 520 | } |
| 521 | |
| 522 | static int |
| 523 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 524 | struct nfs4_state *state, long *timeout) |
| 525 | { |
| 526 | struct nfs4_exception exception = { |
| 527 | .state = state, |
| 528 | }; |
| 529 | |
| 530 | if (task->tk_status >= 0) |
| 531 | return 0; |
| 532 | if (timeout) |
| 533 | exception.timeout = *timeout; |
| 534 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 535 | task->tk_status, |
| 536 | &exception); |
| 537 | if (exception.delay && timeout) |
| 538 | *timeout = exception.timeout; |
| 539 | if (exception.retry) |
| 540 | return -EAGAIN; |
| 541 | return 0; |
| 542 | } |
| 543 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 544 | /* |
| 545 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 546 | * or 'false' otherwise. |
| 547 | */ |
| 548 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 549 | { |
| 550 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 551 | |
| 552 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 553 | flavor == RPC_AUTH_GSS_KRB5P) |
| 554 | return true; |
| 555 | |
| 556 | return false; |
| 557 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 558 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 559 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | spin_lock(&clp->cl_lock); |
| 562 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 563 | clp->cl_last_renewal = timestamp; |
| 564 | spin_unlock(&clp->cl_lock); |
| 565 | } |
| 566 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 567 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 568 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 569 | struct nfs_client *clp = server->nfs_client; |
| 570 | |
| 571 | if (!nfs4_has_session(clp)) |
| 572 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 575 | struct nfs4_call_sync_data { |
| 576 | const struct nfs_server *seq_server; |
| 577 | struct nfs4_sequence_args *seq_args; |
| 578 | struct nfs4_sequence_res *seq_res; |
| 579 | }; |
| 580 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 581 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 582 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 583 | { |
| 584 | args->sa_slot = NULL; |
| 585 | args->sa_cache_this = cache_reply; |
| 586 | args->sa_privileged = 0; |
| 587 | |
| 588 | res->sr_slot = NULL; |
| 589 | } |
| 590 | |
| 591 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 592 | { |
| 593 | args->sa_privileged = 1; |
| 594 | } |
| 595 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 596 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 597 | struct nfs4_sequence_args *args, |
| 598 | struct nfs4_sequence_res *res, |
| 599 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 600 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 601 | struct nfs4_slot *slot; |
| 602 | |
| 603 | /* slot already allocated? */ |
| 604 | if (res->sr_slot != NULL) |
| 605 | goto out_start; |
| 606 | |
| 607 | spin_lock(&tbl->slot_tbl_lock); |
| 608 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 609 | goto out_sleep; |
| 610 | |
| 611 | slot = nfs4_alloc_slot(tbl); |
| 612 | if (IS_ERR(slot)) { |
| 613 | if (slot == ERR_PTR(-ENOMEM)) |
| 614 | task->tk_timeout = HZ >> 2; |
| 615 | goto out_sleep; |
| 616 | } |
| 617 | spin_unlock(&tbl->slot_tbl_lock); |
| 618 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 619 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 620 | args->sa_slot = slot; |
| 621 | res->sr_slot = slot; |
| 622 | |
| 623 | out_start: |
| 624 | rpc_call_start(task); |
| 625 | return 0; |
| 626 | |
| 627 | out_sleep: |
| 628 | if (args->sa_privileged) |
| 629 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 630 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 631 | else |
| 632 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 633 | spin_unlock(&tbl->slot_tbl_lock); |
| 634 | return -EAGAIN; |
| 635 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 636 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 637 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 638 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 639 | { |
| 640 | struct nfs4_slot *slot = res->sr_slot; |
| 641 | struct nfs4_slot_table *tbl; |
| 642 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 643 | tbl = slot->table; |
| 644 | spin_lock(&tbl->slot_tbl_lock); |
| 645 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 646 | nfs4_free_slot(tbl, slot); |
| 647 | spin_unlock(&tbl->slot_tbl_lock); |
| 648 | |
| 649 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static int nfs40_sequence_done(struct rpc_task *task, |
| 653 | struct nfs4_sequence_res *res) |
| 654 | { |
| 655 | if (res->sr_slot != NULL) |
| 656 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 657 | return 1; |
| 658 | } |
| 659 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 660 | #if defined(CONFIG_NFS_V4_1) |
| 661 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 662 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 663 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 664 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 665 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 666 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 667 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 668 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 670 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 671 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 672 | /* Bump the slot sequence number */ |
| 673 | if (slot->seq_done) |
| 674 | slot->seq_nr++; |
| 675 | slot->seq_done = 0; |
| 676 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 677 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 678 | /* Be nice to the server: try to ensure that the last transmitted |
| 679 | * value for highest_user_slotid <= target_highest_slotid |
| 680 | */ |
| 681 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 682 | send_new_highest_used_slotid = true; |
| 683 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 684 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 685 | send_new_highest_used_slotid = false; |
| 686 | goto out_unlock; |
| 687 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 688 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 689 | |
| 690 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 691 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 692 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 693 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 694 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 695 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 696 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 697 | if (waitqueue_active(&tbl->slot_waitq)) |
| 698 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 701 | static int nfs41_sequence_process(struct rpc_task *task, |
| 702 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 703 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 704 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 706 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 707 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 708 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 709 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 710 | if (slot == NULL) |
| 711 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 712 | /* don't increment the sequence number if the task wasn't sent */ |
| 713 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 714 | goto out; |
| 715 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 716 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 717 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 718 | if (slot->interrupted) { |
| 719 | slot->interrupted = 0; |
| 720 | interrupted = true; |
| 721 | } |
| 722 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 723 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 724 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 725 | switch (res->sr_status) { |
| 726 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 727 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 728 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 729 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 730 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 731 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 732 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 733 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 734 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | case 1: |
| 737 | /* |
| 738 | * sr_status remains 1 if an RPC level error occurred. |
| 739 | * The server may or may not have processed the sequence |
| 740 | * operation.. |
| 741 | * Mark the slot as having hosted an interrupted RPC call. |
| 742 | */ |
| 743 | slot->interrupted = 1; |
| 744 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 745 | case -NFS4ERR_DELAY: |
| 746 | /* The server detected a resend of the RPC call and |
| 747 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 748 | * of RFC5661. |
| 749 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 750 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 751 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 752 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 753 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 754 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 755 | case -NFS4ERR_BADSLOT: |
| 756 | /* |
| 757 | * The slot id we used was probably retired. Try again |
| 758 | * using a different slot id. |
| 759 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 760 | goto retry_nowait; |
| 761 | case -NFS4ERR_SEQ_MISORDERED: |
| 762 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 763 | * Was the last operation on this sequence interrupted? |
| 764 | * If so, retry after bumping the sequence number. |
| 765 | */ |
| 766 | if (interrupted) { |
| 767 | ++slot->seq_nr; |
| 768 | goto retry_nowait; |
| 769 | } |
| 770 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 771 | * Could this slot have been previously retired? |
| 772 | * If so, then the server may be expecting seq_nr = 1! |
| 773 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 774 | if (slot->seq_nr != 1) { |
| 775 | slot->seq_nr = 1; |
| 776 | goto retry_nowait; |
| 777 | } |
| 778 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 779 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 780 | ++slot->seq_nr; |
| 781 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 782 | default: |
| 783 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 784 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 785 | } |
| 786 | out: |
| 787 | /* The session may be reset by one of the error handlers. */ |
| 788 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 789 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 790 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | retry_nowait: |
| 792 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 794 | task->tk_status = 0; |
| 795 | ret = 0; |
| 796 | } |
| 797 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 799 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 800 | goto out; |
| 801 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 802 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 803 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 804 | |
| 805 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 806 | { |
| 807 | if (!nfs41_sequence_process(task, res)) |
| 808 | return 0; |
| 809 | if (res->sr_slot != NULL) |
| 810 | nfs41_sequence_free_slot(res); |
| 811 | return 1; |
| 812 | |
| 813 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 814 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 817 | { |
| 818 | if (res->sr_slot == NULL) |
| 819 | return 1; |
| 820 | if (res->sr_slot->table->session != NULL) |
| 821 | return nfs41_sequence_process(task, res); |
| 822 | return nfs40_sequence_done(task, res); |
| 823 | } |
| 824 | |
| 825 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 826 | { |
| 827 | if (res->sr_slot != NULL) { |
| 828 | if (res->sr_slot->table->session != NULL) |
| 829 | nfs41_sequence_free_slot(res); |
| 830 | else |
| 831 | nfs40_sequence_free_slot(res); |
| 832 | } |
| 833 | } |
| 834 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 835 | 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] | 836 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 837 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 839 | if (!res->sr_slot->table->session) |
| 840 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 841 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 844 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 845 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | struct nfs4_sequence_args *args, |
| 847 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 848 | struct rpc_task *task) |
| 849 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 850 | struct nfs4_slot *slot; |
| 851 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 852 | |
| 853 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 854 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 855 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 856 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 857 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 858 | tbl = &session->fc_slot_table; |
| 859 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 860 | task->tk_timeout = 0; |
| 861 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 862 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 863 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 864 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 865 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 866 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 867 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 870 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 871 | if (IS_ERR(slot)) { |
| 872 | /* If out of memory, try again in 1/4 second */ |
| 873 | if (slot == ERR_PTR(-ENOMEM)) |
| 874 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 875 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 876 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 877 | } |
| 878 | spin_unlock(&tbl->slot_tbl_lock); |
| 879 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 880 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 881 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 882 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 883 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 884 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 885 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 886 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 887 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 888 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | /* |
| 890 | * sr_status is only set in decode_sequence, and so will remain |
| 891 | * set to 1 if an rpc level failure occurs. |
| 892 | */ |
| 893 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 894 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 895 | out_success: |
| 896 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 898 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 899 | /* Privileged tasks are queued with top priority */ |
| 900 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 901 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 902 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 903 | else |
| 904 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 905 | spin_unlock(&tbl->slot_tbl_lock); |
| 906 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 907 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 908 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 909 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 910 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 911 | struct nfs4_sequence_args *args, |
| 912 | struct nfs4_sequence_res *res, |
| 913 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 914 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 915 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 916 | int ret = 0; |
| 917 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 918 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 919 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 920 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 921 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 922 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 923 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 924 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 925 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 926 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 927 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 928 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 929 | return ret; |
| 930 | } |
| 931 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 932 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 933 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 934 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 935 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 936 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 937 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 938 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 939 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 942 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 943 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 944 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 945 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 946 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 949 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 950 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 951 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 952 | }; |
| 953 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 954 | #else /* !CONFIG_NFS_V4_1 */ |
| 955 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 956 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 957 | struct nfs4_sequence_args *args, |
| 958 | struct nfs4_sequence_res *res, |
| 959 | struct rpc_task *task) |
| 960 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 961 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 962 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 963 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 964 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 965 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 966 | { |
| 967 | return nfs40_sequence_done(task, res); |
| 968 | } |
| 969 | |
| 970 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 971 | { |
| 972 | if (res->sr_slot != NULL) |
| 973 | nfs40_sequence_free_slot(res); |
| 974 | } |
| 975 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 976 | int nfs4_sequence_done(struct rpc_task *task, |
| 977 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 978 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 979 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 980 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 981 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 982 | |
| 983 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 984 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 985 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 986 | { |
| 987 | struct nfs4_call_sync_data *data = calldata; |
| 988 | nfs4_setup_sequence(data->seq_server, |
| 989 | data->seq_args, data->seq_res, task); |
| 990 | } |
| 991 | |
| 992 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 993 | { |
| 994 | struct nfs4_call_sync_data *data = calldata; |
| 995 | nfs4_sequence_done(task, data->seq_res); |
| 996 | } |
| 997 | |
| 998 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 999 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1000 | .rpc_call_done = nfs40_call_sync_done, |
| 1001 | }; |
| 1002 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1003 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1004 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1006 | struct nfs4_sequence_args *args, |
| 1007 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1008 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1009 | int ret; |
| 1010 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1011 | struct nfs_client *clp = server->nfs_client; |
| 1012 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1013 | .seq_server = server, |
| 1014 | .seq_args = args, |
| 1015 | .seq_res = res, |
| 1016 | }; |
| 1017 | struct rpc_task_setup task_setup = { |
| 1018 | .rpc_client = clnt, |
| 1019 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1020 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1021 | .callback_data = &data |
| 1022 | }; |
| 1023 | |
| 1024 | task = rpc_run_task(&task_setup); |
| 1025 | if (IS_ERR(task)) |
| 1026 | ret = PTR_ERR(task); |
| 1027 | else { |
| 1028 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1029 | rpc_put_task(task); |
| 1030 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1034 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1035 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1036 | struct rpc_message *msg, |
| 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res, |
| 1039 | int cache_reply) |
| 1040 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1041 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1042 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
| 1045 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1046 | { |
| 1047 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1048 | |
| 1049 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1050 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1051 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1053 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1054 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1055 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | spin_unlock(&dir->i_lock); |
| 1057 | } |
| 1058 | |
| 1059 | struct nfs4_opendata { |
| 1060 | struct kref kref; |
| 1061 | struct nfs_openargs o_arg; |
| 1062 | struct nfs_openres o_res; |
| 1063 | struct nfs_open_confirmargs c_arg; |
| 1064 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1065 | struct nfs4_string owner_name; |
| 1066 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1067 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1069 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1071 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | struct nfs4_state_owner *owner; |
| 1073 | struct nfs4_state *state; |
| 1074 | struct iattr attrs; |
| 1075 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1076 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1077 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1078 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1079 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | int cancelled; |
| 1081 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1082 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1083 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1084 | int err, struct nfs4_exception *exception) |
| 1085 | { |
| 1086 | if (err != -EINVAL) |
| 1087 | return false; |
| 1088 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1089 | return false; |
| 1090 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1091 | exception->retry = 1; |
| 1092 | return true; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1095 | static u32 |
| 1096 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1097 | fmode_t fmode, int openflags) |
| 1098 | { |
| 1099 | u32 res = 0; |
| 1100 | |
| 1101 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1102 | case FMODE_READ: |
| 1103 | res = NFS4_SHARE_ACCESS_READ; |
| 1104 | break; |
| 1105 | case FMODE_WRITE: |
| 1106 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1107 | break; |
| 1108 | case FMODE_READ|FMODE_WRITE: |
| 1109 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1110 | } |
| 1111 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1112 | goto out; |
| 1113 | /* Want no delegation if we're using O_DIRECT */ |
| 1114 | if (openflags & O_DIRECT) |
| 1115 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1116 | out: |
| 1117 | return res; |
| 1118 | } |
| 1119 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1120 | static enum open_claim_type4 |
| 1121 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1122 | enum open_claim_type4 claim) |
| 1123 | { |
| 1124 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1125 | return claim; |
| 1126 | switch (claim) { |
| 1127 | default: |
| 1128 | return claim; |
| 1129 | case NFS4_OPEN_CLAIM_FH: |
| 1130 | return NFS4_OPEN_CLAIM_NULL; |
| 1131 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1132 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1133 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1134 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1135 | } |
| 1136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1139 | { |
| 1140 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1141 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1142 | p->o_res.seqid = p->o_arg.seqid; |
| 1143 | p->c_res.seqid = p->c_arg.seqid; |
| 1144 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1145 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1146 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1147 | 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] | 1148 | } |
| 1149 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1150 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1151 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1152 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1153 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1154 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1155 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1156 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1157 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1158 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1159 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1160 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | struct nfs4_opendata *p; |
| 1162 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1163 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1164 | if (p == NULL) |
| 1165 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1166 | |
| 1167 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1168 | if (IS_ERR(p->f_label)) |
| 1169 | goto err_free_p; |
| 1170 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1171 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1172 | if (IS_ERR(p->a_label)) |
| 1173 | goto err_free_f; |
| 1174 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1175 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1176 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1177 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1178 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1179 | nfs_sb_active(dentry->d_sb); |
| 1180 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1181 | p->dir = parent; |
| 1182 | p->owner = sp; |
| 1183 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1184 | p->o_arg.open_flags = flags; |
| 1185 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1186 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1187 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1188 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1189 | * will return permission denied for all bits until close */ |
| 1190 | if (!(flags & O_EXCL)) { |
| 1191 | /* ask server to check for all possible rights as results |
| 1192 | * are cached */ |
| 1193 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1194 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1195 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1196 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1197 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1198 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1199 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1201 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1202 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1203 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1204 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1205 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1206 | case NFS4_OPEN_CLAIM_NULL: |
| 1207 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1208 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1209 | p->o_arg.fh = NFS_FH(dir); |
| 1210 | break; |
| 1211 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1212 | case NFS4_OPEN_CLAIM_FH: |
| 1213 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1214 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1215 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1216 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1217 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1218 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1219 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | p->o_arg.u.attrs = &p->attrs; |
| 1221 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1222 | |
| 1223 | verf[0] = jiffies; |
| 1224 | verf[1] = current->pid; |
| 1225 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1226 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1227 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1228 | p->c_arg.fh = &p->o_res.fh; |
| 1229 | p->c_arg.stateid = &p->o_res.stateid; |
| 1230 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1231 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1232 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1233 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1234 | |
| 1235 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1236 | nfs4_label_free(p->a_label); |
| 1237 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1238 | nfs4_label_free(p->f_label); |
| 1239 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1240 | kfree(p); |
| 1241 | err: |
| 1242 | dput(parent); |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1246 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1247 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1248 | struct nfs4_opendata *p = container_of(kref, |
| 1249 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1250 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1251 | |
| 1252 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1253 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1254 | if (p->state != NULL) |
| 1255 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1256 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1257 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1258 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1259 | nfs4_label_free(p->f_label); |
| 1260 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1261 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1262 | dput(p->dentry); |
| 1263 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1264 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1265 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1266 | kfree(p); |
| 1267 | } |
| 1268 | |
| 1269 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1270 | { |
| 1271 | if (p != NULL) |
| 1272 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1275 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1276 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1277 | int ret; |
| 1278 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1279 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1283 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1284 | fmode_t fmode) |
| 1285 | { |
| 1286 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1287 | case FMODE_READ|FMODE_WRITE: |
| 1288 | return state->n_rdwr != 0; |
| 1289 | case FMODE_WRITE: |
| 1290 | return state->n_wronly != 0; |
| 1291 | case FMODE_READ: |
| 1292 | return state->n_rdonly != 0; |
| 1293 | } |
| 1294 | WARN_ON_ONCE(1); |
| 1295 | return false; |
| 1296 | } |
| 1297 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1298 | 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] | 1299 | { |
| 1300 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1301 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1302 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1303 | goto out; |
| 1304 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1305 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1306 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1307 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1308 | break; |
| 1309 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1310 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1311 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1312 | break; |
| 1313 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1314 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1315 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1316 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1317 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1318 | return ret; |
| 1319 | } |
| 1320 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1321 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1322 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1323 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1324 | if (delegation == NULL) |
| 1325 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1326 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1327 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1328 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1329 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1330 | switch (claim) { |
| 1331 | case NFS4_OPEN_CLAIM_NULL: |
| 1332 | case NFS4_OPEN_CLAIM_FH: |
| 1333 | break; |
| 1334 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1335 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1336 | break; |
| 1337 | default: |
| 1338 | return 0; |
| 1339 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1340 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1341 | return 1; |
| 1342 | } |
| 1343 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1345 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1347 | case FMODE_WRITE: |
| 1348 | state->n_wronly++; |
| 1349 | break; |
| 1350 | case FMODE_READ: |
| 1351 | state->n_rdonly++; |
| 1352 | break; |
| 1353 | case FMODE_READ|FMODE_WRITE: |
| 1354 | state->n_rdwr++; |
| 1355 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1356 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1359 | 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] | 1360 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1361 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1362 | bool need_recover = false; |
| 1363 | |
| 1364 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1365 | need_recover = true; |
| 1366 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1367 | need_recover = true; |
| 1368 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1369 | need_recover = true; |
| 1370 | if (need_recover) |
| 1371 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1372 | } |
| 1373 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1374 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1375 | nfs4_stateid *stateid) |
| 1376 | { |
| 1377 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1378 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1379 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1380 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1381 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1382 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1383 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1384 | return true; |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1388 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1389 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1390 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1391 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1392 | if (state->n_wronly) |
| 1393 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1394 | if (state->n_rdonly) |
| 1395 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1396 | if (state->n_rdwr) |
| 1397 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1398 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1401 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1402 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1403 | nfs4_stateid *stateid, fmode_t fmode) |
| 1404 | { |
| 1405 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1406 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1407 | case FMODE_WRITE: |
| 1408 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1409 | break; |
| 1410 | case FMODE_READ: |
| 1411 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1412 | break; |
| 1413 | case 0: |
| 1414 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1415 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1416 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1417 | } |
| 1418 | if (stateid == NULL) |
| 1419 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1420 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1421 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1422 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1423 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1424 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1425 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1426 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1427 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1428 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1429 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1430 | } |
| 1431 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1432 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1433 | nfs4_stateid *arg_stateid, |
| 1434 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1435 | { |
| 1436 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1437 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1438 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1439 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1440 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1441 | } |
| 1442 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1443 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1444 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1445 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1446 | case FMODE_READ: |
| 1447 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1448 | break; |
| 1449 | case FMODE_WRITE: |
| 1450 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1451 | break; |
| 1452 | case FMODE_READ|FMODE_WRITE: |
| 1453 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1454 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1455 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1456 | return; |
| 1457 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1458 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1459 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1464 | /* |
| 1465 | * Protect the call to nfs4_state_set_mode_locked and |
| 1466 | * serialise the stateid update |
| 1467 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1468 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1469 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1470 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1471 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1472 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1473 | } |
| 1474 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1476 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1477 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1478 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1481 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1482 | { |
| 1483 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1484 | struct nfs_delegation *deleg_cur; |
| 1485 | int ret = 0; |
| 1486 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1487 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1488 | |
| 1489 | rcu_read_lock(); |
| 1490 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1491 | if (deleg_cur == NULL) |
| 1492 | goto no_delegation; |
| 1493 | |
| 1494 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1495 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1496 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1497 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1498 | goto no_delegation_unlock; |
| 1499 | |
| 1500 | if (delegation == NULL) |
| 1501 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1502 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1503 | goto no_delegation_unlock; |
| 1504 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1505 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1506 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1507 | ret = 1; |
| 1508 | no_delegation_unlock: |
| 1509 | spin_unlock(&deleg_cur->lock); |
| 1510 | no_delegation: |
| 1511 | rcu_read_unlock(); |
| 1512 | |
| 1513 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1514 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1515 | ret = 1; |
| 1516 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1517 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1518 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1523 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1524 | const nfs4_stateid *stateid) |
| 1525 | { |
| 1526 | struct nfs4_state *state = lsp->ls_state; |
| 1527 | bool ret = false; |
| 1528 | |
| 1529 | spin_lock(&state->state_lock); |
| 1530 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1531 | goto out_noupdate; |
| 1532 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1533 | goto out_noupdate; |
| 1534 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1535 | ret = true; |
| 1536 | out_noupdate: |
| 1537 | spin_unlock(&state->state_lock); |
| 1538 | return ret; |
| 1539 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1540 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1542 | { |
| 1543 | struct nfs_delegation *delegation; |
| 1544 | |
| 1545 | rcu_read_lock(); |
| 1546 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1547 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | rcu_read_unlock(); |
| 1549 | return; |
| 1550 | } |
| 1551 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1552 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1555 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1556 | { |
| 1557 | struct nfs4_state *state = opendata->state; |
| 1558 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1559 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1560 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1561 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1562 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1563 | nfs4_stateid stateid; |
| 1564 | int ret = -EAGAIN; |
| 1565 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1566 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1567 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1568 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1569 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1570 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1571 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1572 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1573 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | rcu_read_lock(); |
| 1575 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1576 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1577 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1578 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1579 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1580 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1581 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1582 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1583 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1584 | if (!opendata->is_recover) { |
| 1585 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1586 | if (ret != 0) |
| 1587 | goto out; |
| 1588 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1589 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1590 | |
| 1591 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1592 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1593 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1594 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1595 | out: |
| 1596 | return ERR_PTR(ret); |
| 1597 | out_return_state: |
| 1598 | atomic_inc(&state->count); |
| 1599 | return state; |
| 1600 | } |
| 1601 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1602 | static void |
| 1603 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1604 | { |
| 1605 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1606 | struct nfs_delegation *delegation; |
| 1607 | int delegation_flags = 0; |
| 1608 | |
| 1609 | rcu_read_lock(); |
| 1610 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1611 | if (delegation) |
| 1612 | delegation_flags = delegation->flags; |
| 1613 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1614 | switch (data->o_arg.claim) { |
| 1615 | default: |
| 1616 | break; |
| 1617 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1618 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1619 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1620 | "returning a delegation for " |
| 1621 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1622 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1623 | return; |
| 1624 | } |
| 1625 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1626 | nfs_inode_set_delegation(state->inode, |
| 1627 | data->owner->so_cred, |
| 1628 | &data->o_res); |
| 1629 | else |
| 1630 | nfs_inode_reclaim_delegation(state->inode, |
| 1631 | data->owner->so_cred, |
| 1632 | &data->o_res); |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1637 | * and update the nfs4_state. |
| 1638 | */ |
| 1639 | static struct nfs4_state * |
| 1640 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1641 | { |
| 1642 | struct inode *inode = data->state->inode; |
| 1643 | struct nfs4_state *state = data->state; |
| 1644 | int ret; |
| 1645 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1646 | if (!data->rpc_done) { |
| 1647 | if (data->rpc_status) { |
| 1648 | ret = data->rpc_status; |
| 1649 | goto err; |
| 1650 | } |
| 1651 | /* cached opens have already been processed */ |
| 1652 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1656 | if (ret) |
| 1657 | goto err; |
| 1658 | |
| 1659 | if (data->o_res.delegation_type != 0) |
| 1660 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1661 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1662 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1663 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1664 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1665 | |
| 1666 | return state; |
| 1667 | err: |
| 1668 | return ERR_PTR(ret); |
| 1669 | |
| 1670 | } |
| 1671 | |
| 1672 | static struct nfs4_state * |
| 1673 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1674 | { |
| 1675 | struct inode *inode; |
| 1676 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1677 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1680 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1681 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | goto out; |
| 1683 | } |
| 1684 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1685 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1687 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1688 | 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] | 1689 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1690 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1691 | goto err; |
| 1692 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | state = nfs4_get_open_state(inode, data->owner); |
| 1694 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1695 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1696 | if (data->o_res.delegation_type != 0) |
| 1697 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1698 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1699 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1701 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1702 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | err_put_inode: |
| 1705 | iput(inode); |
| 1706 | err: |
| 1707 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1710 | static struct nfs4_state * |
| 1711 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1712 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1713 | struct nfs4_state *ret; |
| 1714 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1715 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1716 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1717 | else |
| 1718 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1719 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1720 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1724 | { |
| 1725 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1726 | struct nfs_open_context *ctx; |
| 1727 | |
| 1728 | spin_lock(&state->inode->i_lock); |
| 1729 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1730 | if (ctx->state != state) |
| 1731 | continue; |
| 1732 | get_nfs_open_context(ctx); |
| 1733 | spin_unlock(&state->inode->i_lock); |
| 1734 | return ctx; |
| 1735 | } |
| 1736 | spin_unlock(&state->inode->i_lock); |
| 1737 | return ERR_PTR(-ENOENT); |
| 1738 | } |
| 1739 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1740 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1741 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1742 | { |
| 1743 | struct nfs4_opendata *opendata; |
| 1744 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1745 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1746 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1747 | if (opendata == NULL) |
| 1748 | return ERR_PTR(-ENOMEM); |
| 1749 | opendata->state = state; |
| 1750 | atomic_inc(&state->count); |
| 1751 | return opendata; |
| 1752 | } |
| 1753 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1754 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1755 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1756 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1757 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | int ret; |
| 1759 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1760 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1761 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1762 | opendata->o_arg.open_flags = 0; |
| 1763 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1764 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1765 | NFS_SB(opendata->dentry->d_sb), |
| 1766 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1767 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1768 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1769 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1770 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1771 | if (ret != 0) |
| 1772 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1773 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1774 | if (IS_ERR(newstate)) |
| 1775 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1776 | if (newstate != opendata->state) |
| 1777 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1778 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1779 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1783 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | int ret; |
| 1785 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1786 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1787 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1788 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1789 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1791 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1792 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1793 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1794 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1795 | if (ret != 0) |
| 1796 | return ret; |
| 1797 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1798 | if (ret != 0) |
| 1799 | return ret; |
| 1800 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1801 | if (ret != 0) |
| 1802 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1803 | /* |
| 1804 | * We may have performed cached opens for all three recoveries. |
| 1805 | * Check if we need to update the current stateid. |
| 1806 | */ |
| 1807 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1808 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1809 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1810 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1811 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1812 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1813 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * OPEN_RECLAIM: |
| 1819 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1821 | 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] | 1822 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1823 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1825 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | int status; |
| 1827 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1828 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1829 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1830 | if (IS_ERR(opendata)) |
| 1831 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1832 | rcu_read_lock(); |
| 1833 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1834 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1835 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1836 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1837 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1838 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1839 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | return status; |
| 1841 | } |
| 1842 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1843 | 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] | 1844 | { |
| 1845 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1846 | struct nfs4_exception exception = { }; |
| 1847 | int err; |
| 1848 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1849 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1850 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1851 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1852 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1853 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } while (exception.retry); |
| 1857 | return err; |
| 1858 | } |
| 1859 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1861 | { |
| 1862 | struct nfs_open_context *ctx; |
| 1863 | int ret; |
| 1864 | |
| 1865 | ctx = nfs4_state_find_open_context(state); |
| 1866 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1867 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1868 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1869 | put_nfs_open_context(ctx); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1873 | 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] | 1874 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1875 | switch (err) { |
| 1876 | default: |
| 1877 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1878 | "%d.\n", __func__, err); |
| 1879 | case 0: |
| 1880 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1881 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1882 | case -ESTALE: |
| 1883 | break; |
| 1884 | case -NFS4ERR_BADSESSION: |
| 1885 | case -NFS4ERR_BADSLOT: |
| 1886 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1887 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1888 | case -NFS4ERR_DEADSESSION: |
| 1889 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1890 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1891 | return -EAGAIN; |
| 1892 | case -NFS4ERR_STALE_CLIENTID: |
| 1893 | case -NFS4ERR_STALE_STATEID: |
| 1894 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1895 | case -NFS4ERR_EXPIRED: |
| 1896 | /* Don't recall a delegation if it was lost */ |
| 1897 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1898 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1899 | case -NFS4ERR_MOVED: |
| 1900 | nfs4_schedule_migration_recovery(server); |
| 1901 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1902 | case -NFS4ERR_LEASE_MOVED: |
| 1903 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1904 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1905 | case -NFS4ERR_DELEG_REVOKED: |
| 1906 | case -NFS4ERR_ADMIN_REVOKED: |
| 1907 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1908 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1909 | nfs_inode_find_state_and_recover(state->inode, |
| 1910 | stateid); |
| 1911 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1912 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1913 | case -NFS4ERR_DELAY: |
| 1914 | case -NFS4ERR_GRACE: |
| 1915 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1916 | ssleep(1); |
| 1917 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1918 | case -ENOMEM: |
| 1919 | case -NFS4ERR_DENIED: |
| 1920 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1921 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | return err; |
| 1924 | } |
| 1925 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1926 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1927 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1928 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1929 | { |
| 1930 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1931 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1932 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1933 | |
| 1934 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1935 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1936 | if (IS_ERR(opendata)) |
| 1937 | return PTR_ERR(opendata); |
| 1938 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1939 | write_seqlock(&state->seqlock); |
| 1940 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1943 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1944 | case FMODE_READ|FMODE_WRITE: |
| 1945 | case FMODE_WRITE: |
| 1946 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1947 | if (err) |
| 1948 | break; |
| 1949 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1950 | if (err) |
| 1951 | break; |
| 1952 | case FMODE_READ: |
| 1953 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1954 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1955 | nfs4_opendata_put(opendata); |
| 1956 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1957 | } |
| 1958 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1959 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1960 | { |
| 1961 | struct nfs4_opendata *data = calldata; |
| 1962 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1963 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1964 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1967 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1968 | { |
| 1969 | struct nfs4_opendata *data = calldata; |
| 1970 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1971 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1972 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1973 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1974 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1975 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1976 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1977 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1978 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1979 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static void nfs4_open_confirm_release(void *calldata) |
| 1983 | { |
| 1984 | struct nfs4_opendata *data = calldata; |
| 1985 | struct nfs4_state *state = NULL; |
| 1986 | |
| 1987 | /* If this request hasn't been cancelled, do nothing */ |
| 1988 | if (data->cancelled == 0) |
| 1989 | goto out_free; |
| 1990 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1991 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1992 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1993 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1994 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1995 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1996 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1997 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2001 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2002 | .rpc_call_done = nfs4_open_confirm_done, |
| 2003 | .rpc_release = nfs4_open_confirm_release, |
| 2004 | }; |
| 2005 | |
| 2006 | /* |
| 2007 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2008 | */ |
| 2009 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2010 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2011 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2012 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2013 | struct rpc_message msg = { |
| 2014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2015 | .rpc_argp = &data->c_arg, |
| 2016 | .rpc_resp = &data->c_res, |
| 2017 | .rpc_cred = data->owner->so_cred, |
| 2018 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2019 | struct rpc_task_setup task_setup_data = { |
| 2020 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2021 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | .callback_ops = &nfs4_open_confirm_ops, |
| 2023 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2024 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .flags = RPC_TASK_ASYNC, |
| 2026 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | int status; |
| 2028 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2029 | 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] | 2030 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2031 | data->rpc_done = 0; |
| 2032 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2033 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2034 | if (data->is_recover) |
| 2035 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2036 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2037 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2038 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2039 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2040 | if (status != 0) { |
| 2041 | data->cancelled = 1; |
| 2042 | smp_wmb(); |
| 2043 | } else |
| 2044 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2045 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | return status; |
| 2047 | } |
| 2048 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2049 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2051 | struct nfs4_opendata *data = calldata; |
| 2052 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2053 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2054 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2055 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2056 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2057 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2058 | /* |
| 2059 | * Check if we still need to send an OPEN call, or if we can use |
| 2060 | * a delegation instead. |
| 2061 | */ |
| 2062 | if (data->state != NULL) { |
| 2063 | struct nfs_delegation *delegation; |
| 2064 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2065 | 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] | 2066 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2067 | rcu_read_lock(); |
| 2068 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2069 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2070 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2071 | rcu_read_unlock(); |
| 2072 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2073 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2074 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2075 | switch (claim) { |
| 2076 | default: |
| 2077 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2078 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2079 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2080 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2081 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2082 | case NFS4_OPEN_CLAIM_FH: |
| 2083 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2084 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2085 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2086 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2087 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2088 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2089 | &data->o_res.seq_res, |
| 2090 | task) != 0) |
| 2091 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2092 | |
| 2093 | /* Set the create mode (note dependency on the session type) */ |
| 2094 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2095 | if (data->o_arg.open_flags & O_EXCL) { |
| 2096 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2097 | if (nfs4_has_persistent_session(clp)) |
| 2098 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2099 | else if (clp->cl_mvops->minor_version > 0) |
| 2100 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2101 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2102 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2103 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2104 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2105 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2106 | out_no_action: |
| 2107 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2108 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2109 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2112 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2113 | { |
| 2114 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2116 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2117 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2118 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2119 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2120 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2121 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2122 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2123 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2124 | case S_IFREG: |
| 2125 | break; |
| 2126 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2127 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2128 | break; |
| 2129 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2130 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2133 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2134 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2135 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2136 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2137 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2138 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2139 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2140 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2141 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | static void nfs4_open_release(void *calldata) |
| 2144 | { |
| 2145 | struct nfs4_opendata *data = calldata; |
| 2146 | struct nfs4_state *state = NULL; |
| 2147 | |
| 2148 | /* If this request hasn't been cancelled, do nothing */ |
| 2149 | if (data->cancelled == 0) |
| 2150 | goto out_free; |
| 2151 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2152 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2153 | goto out_free; |
| 2154 | /* In case we need an open_confirm, no cleanup! */ |
| 2155 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2156 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2157 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2158 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2159 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2161 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2165 | .rpc_call_prepare = nfs4_open_prepare, |
| 2166 | .rpc_call_done = nfs4_open_done, |
| 2167 | .rpc_release = nfs4_open_release, |
| 2168 | }; |
| 2169 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2170 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2171 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2172 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2173 | struct nfs_server *server = NFS_SERVER(dir); |
| 2174 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2175 | struct nfs_openres *o_res = &data->o_res; |
| 2176 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2177 | struct rpc_message msg = { |
| 2178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2179 | .rpc_argp = o_arg, |
| 2180 | .rpc_resp = o_res, |
| 2181 | .rpc_cred = data->owner->so_cred, |
| 2182 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2183 | struct rpc_task_setup task_setup_data = { |
| 2184 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2185 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2186 | .callback_ops = &nfs4_open_ops, |
| 2187 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2188 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | .flags = RPC_TASK_ASYNC, |
| 2190 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | int status; |
| 2192 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2193 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2194 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2195 | data->rpc_done = 0; |
| 2196 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2197 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2198 | data->is_recover = 0; |
| 2199 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2200 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2201 | data->is_recover = 1; |
| 2202 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2203 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2204 | if (IS_ERR(task)) |
| 2205 | return PTR_ERR(task); |
| 2206 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2207 | if (status != 0) { |
| 2208 | data->cancelled = 1; |
| 2209 | smp_wmb(); |
| 2210 | } else |
| 2211 | status = data->rpc_status; |
| 2212 | rpc_put_task(task); |
| 2213 | |
| 2214 | return status; |
| 2215 | } |
| 2216 | |
| 2217 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2218 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2219 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2220 | struct nfs_openres *o_res = &data->o_res; |
| 2221 | int status; |
| 2222 | |
| 2223 | status = nfs4_run_open_task(data, 1); |
| 2224 | if (status != 0 || !data->rpc_done) |
| 2225 | return status; |
| 2226 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2227 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2228 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2229 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2230 | status = _nfs4_proc_open_confirm(data); |
| 2231 | if (status != 0) |
| 2232 | return status; |
| 2233 | } |
| 2234 | |
| 2235 | return status; |
| 2236 | } |
| 2237 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2238 | /* |
| 2239 | * Additional permission checks in order to distinguish between an |
| 2240 | * open for read, and an open for execute. This works around the |
| 2241 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2242 | * the same. |
| 2243 | * Note that in the non-execute case, we want to turn off permission |
| 2244 | * checking if we just created a new file (POSIX open() semantics). |
| 2245 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2246 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2247 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2248 | struct nfs4_state *state, fmode_t fmode, |
| 2249 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2250 | { |
| 2251 | struct nfs_access_entry cache; |
| 2252 | u32 mask; |
| 2253 | |
| 2254 | /* access call failed or for some reason the server doesn't |
| 2255 | * support any access modes -- defer access call until later */ |
| 2256 | if (opendata->o_res.access_supported == 0) |
| 2257 | return 0; |
| 2258 | |
| 2259 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2260 | /* |
| 2261 | * Use openflags to check for exec, because fmode won't |
| 2262 | * always have FMODE_EXEC set when file open for exec. |
| 2263 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2264 | if (openflags & __FMODE_EXEC) { |
| 2265 | /* ONLY check for exec rights */ |
| 2266 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2267 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2268 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2269 | |
| 2270 | cache.cred = cred; |
| 2271 | cache.jiffies = jiffies; |
| 2272 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2273 | nfs_access_add_cache(state->inode, &cache); |
| 2274 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2275 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2276 | return 0; |
| 2277 | |
| 2278 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2279 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2280 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2283 | /* |
| 2284 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2285 | */ |
| 2286 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2287 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2288 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2289 | struct nfs_server *server = NFS_SERVER(dir); |
| 2290 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2291 | struct nfs_openres *o_res = &data->o_res; |
| 2292 | int status; |
| 2293 | |
| 2294 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2295 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2296 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2297 | if (status != 0) { |
| 2298 | if (status == -NFS4ERR_BADNAME && |
| 2299 | !(o_arg->open_flags & O_CREAT)) |
| 2300 | return -ENOENT; |
| 2301 | return status; |
| 2302 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2303 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2304 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2305 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2306 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2307 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2308 | if (o_arg->open_flags & O_EXCL) |
| 2309 | data->file_created = 1; |
| 2310 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2311 | data->file_created = 1; |
| 2312 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2313 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2314 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2316 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | } |
| 2320 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2321 | 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] | 2322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2325 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2326 | { |
| 2327 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2328 | } |
| 2329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | /* |
| 2331 | * OPEN_EXPIRED: |
| 2332 | * reclaim state on the server after a network partition. |
| 2333 | * Assumes caller holds the appropriate lock |
| 2334 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2335 | 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] | 2336 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2337 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2338 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2340 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2341 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2342 | if (IS_ERR(opendata)) |
| 2343 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2344 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2345 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2346 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2347 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2351 | 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] | 2352 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2353 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2354 | struct nfs4_exception exception = { }; |
| 2355 | int err; |
| 2356 | |
| 2357 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2358 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2359 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2360 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2361 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2362 | switch (err) { |
| 2363 | default: |
| 2364 | goto out; |
| 2365 | case -NFS4ERR_GRACE: |
| 2366 | case -NFS4ERR_DELAY: |
| 2367 | nfs4_handle_exception(server, err, &exception); |
| 2368 | err = 0; |
| 2369 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2370 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2371 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2372 | return err; |
| 2373 | } |
| 2374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2378 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2380 | ctx = nfs4_state_find_open_context(state); |
| 2381 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2382 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2383 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2384 | put_nfs_open_context(ctx); |
| 2385 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2388 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2389 | { |
| 2390 | nfs_remove_bad_delegation(state->inode); |
| 2391 | write_seqlock(&state->seqlock); |
| 2392 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2393 | write_sequnlock(&state->seqlock); |
| 2394 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2395 | } |
| 2396 | |
| 2397 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2398 | { |
| 2399 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2400 | nfs_finish_clear_delegation_stateid(state); |
| 2401 | } |
| 2402 | |
| 2403 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2404 | { |
| 2405 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2406 | nfs40_clear_delegation_stateid(state); |
| 2407 | return nfs4_open_expired(sp, state); |
| 2408 | } |
| 2409 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2410 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2411 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2412 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2413 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2414 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2415 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2416 | struct rpc_cred *cred; |
| 2417 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2418 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2419 | /* Get the delegation credential for use by test/free_stateid */ |
| 2420 | rcu_read_lock(); |
| 2421 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2422 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2423 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2424 | return; |
| 2425 | } |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2426 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2427 | rcu_read_unlock(); |
| 2428 | nfs_finish_clear_delegation_stateid(state); |
| 2429 | return; |
| 2430 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2431 | |
| 2432 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2433 | cred = get_rpccred(delegation->cred); |
| 2434 | rcu_read_unlock(); |
| 2435 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2436 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2437 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2438 | if (status != NFS_OK) { |
| 2439 | /* Free the stateid unless the server explicitly |
| 2440 | * informs us the stateid is unrecognized. */ |
| 2441 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2442 | nfs41_free_stateid(server, &stateid, cred); |
| 2443 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2444 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2445 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2446 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2451 | * |
| 2452 | * @state: NFSv4 state for an inode |
| 2453 | * |
| 2454 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2455 | * Otherwise a negative NFS4ERR value is returned. |
| 2456 | */ |
| 2457 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2458 | { |
| 2459 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2460 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2461 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2462 | int status; |
| 2463 | |
| 2464 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2465 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2466 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2467 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2468 | return -NFS4ERR_BAD_STATEID; |
| 2469 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2470 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2471 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2472 | if (status != NFS_OK) { |
| 2473 | /* Free the stateid unless the server explicitly |
| 2474 | * informs us the stateid is unrecognized. */ |
| 2475 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2476 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2477 | |
| 2478 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2479 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2480 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2481 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2482 | } |
| 2483 | return status; |
| 2484 | } |
| 2485 | |
| 2486 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2487 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2488 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2489 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2490 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2491 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2492 | if (status != NFS_OK) |
| 2493 | status = nfs4_open_expired(sp, state); |
| 2494 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2495 | } |
| 2496 | #endif |
| 2497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2499 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2500 | * fields corresponding to attributes that were used to store the verifier. |
| 2501 | * Make sure we clobber those fields in the later setattr call |
| 2502 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2503 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2504 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2505 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2506 | const u32 *attrset = opendata->o_res.attrset; |
| 2507 | |
| 2508 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2509 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2510 | sattr->ia_valid |= ATTR_ATIME; |
| 2511 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2512 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2513 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2514 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2515 | |
| 2516 | /* Except MODE, it seems harmless of setting twice. */ |
| 2517 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2518 | sattr->ia_valid &= ~ATTR_MODE; |
| 2519 | |
| 2520 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2521 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2522 | } |
| 2523 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2524 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2525 | fmode_t fmode, |
| 2526 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2527 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2528 | { |
| 2529 | struct nfs4_state_owner *sp = opendata->owner; |
| 2530 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2531 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2532 | struct nfs4_state *state; |
| 2533 | unsigned int seq; |
| 2534 | int ret; |
| 2535 | |
| 2536 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2537 | |
| 2538 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2539 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2540 | goto out; |
| 2541 | |
| 2542 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2543 | ret = PTR_ERR(state); |
| 2544 | if (IS_ERR(state)) |
| 2545 | goto out; |
| 2546 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2547 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2548 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2549 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2550 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2551 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2552 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2553 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2554 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2555 | alias = d_exact_alias(dentry, state->inode); |
| 2556 | if (!alias) |
| 2557 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2558 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2559 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2560 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2561 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2562 | } |
| 2563 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2564 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2565 | } |
| 2566 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2567 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2568 | if (ret != 0) |
| 2569 | goto out; |
| 2570 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2571 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2572 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2573 | nfs_inode_attach_open_context(ctx); |
| 2574 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2575 | nfs4_schedule_stateid_recovery(server, state); |
| 2576 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2577 | out: |
| 2578 | return ret; |
| 2579 | } |
| 2580 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2581 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2582 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2584 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2585 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2586 | int flags, |
| 2587 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2588 | struct nfs4_label *label, |
| 2589 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | { |
| 2591 | struct nfs4_state_owner *sp; |
| 2592 | struct nfs4_state *state = NULL; |
| 2593 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2594 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2595 | struct dentry *dentry = ctx->dentry; |
| 2596 | struct rpc_cred *cred = ctx->cred; |
| 2597 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2598 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2599 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2600 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2601 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | |
| 2603 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2605 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2606 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2608 | goto out_err; |
| 2609 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2610 | status = nfs4_recover_expired_lease(server); |
| 2611 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2612 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2613 | if (d_really_is_positive(dentry)) |
| 2614 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2615 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2616 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2617 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2618 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2619 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2620 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2621 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2623 | if (label) { |
| 2624 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2625 | if (IS_ERR(olabel)) { |
| 2626 | status = PTR_ERR(olabel); |
| 2627 | goto err_opendata_put; |
| 2628 | } |
| 2629 | } |
| 2630 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2631 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2632 | if (!opendata->f_attr.mdsthreshold) { |
| 2633 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2634 | if (!opendata->f_attr.mdsthreshold) |
| 2635 | goto err_free_label; |
| 2636 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2637 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2638 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2639 | if (d_really_is_positive(dentry)) |
| 2640 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2641 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2642 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2643 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2644 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2645 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2646 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2647 | 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] | 2648 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2649 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2650 | /* |
| 2651 | * send create attributes which was not set by open |
| 2652 | * with an extra setattr. |
| 2653 | */ |
| 2654 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2655 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2656 | status = nfs4_do_setattr(state->inode, cred, |
| 2657 | opendata->o_res.f_attr, sattr, |
| 2658 | state, label, olabel); |
| 2659 | if (status == 0) { |
| 2660 | nfs_setattr_update_inode(state->inode, sattr, |
| 2661 | opendata->o_res.f_attr); |
| 2662 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2663 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2664 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2665 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2666 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2667 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2668 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2669 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2670 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2671 | opendata->f_attr.mdsthreshold = NULL; |
| 2672 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2673 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2674 | nfs4_label_free(olabel); |
| 2675 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2676 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2679 | err_free_label: |
| 2680 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2681 | err_opendata_put: |
| 2682 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2683 | err_put_state_owner: |
| 2684 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | return status; |
| 2687 | } |
| 2688 | |
| 2689 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2690 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2691 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2692 | int flags, |
| 2693 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2694 | struct nfs4_label *label, |
| 2695 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2697 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | struct nfs4_exception exception = { }; |
| 2699 | struct nfs4_state *res; |
| 2700 | int status; |
| 2701 | |
| 2702 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2703 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2704 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2705 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | if (status == 0) |
| 2707 | break; |
| 2708 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2709 | * book-keeping w.r.t. state-changing operations |
| 2710 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2711 | * It is actually a sign of a bug on the client or on the server. |
| 2712 | * |
| 2713 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2714 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | * have unhashed the old state_owner for us, and that we can |
| 2716 | * therefore safely retry using a new one. We should still warn |
| 2717 | * the user though... |
| 2718 | */ |
| 2719 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2720 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2721 | " returned a bad sequence-id error!\n", |
| 2722 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | exception.retry = 1; |
| 2724 | continue; |
| 2725 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2726 | /* |
| 2727 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2728 | * state before it received the OPEN_CONFIRM. |
| 2729 | * Recover by retrying the request as per the discussion |
| 2730 | * on Page 181 of RFC3530. |
| 2731 | */ |
| 2732 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2733 | exception.retry = 1; |
| 2734 | continue; |
| 2735 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2736 | if (status == -EAGAIN) { |
| 2737 | /* We must have found a delegation */ |
| 2738 | exception.retry = 1; |
| 2739 | continue; |
| 2740 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2741 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2742 | continue; |
| 2743 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | status, &exception)); |
| 2745 | } while (exception.retry); |
| 2746 | return res; |
| 2747 | } |
| 2748 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2749 | static int _nfs4_do_setattr(struct inode *inode, |
| 2750 | struct nfs_setattrargs *arg, |
| 2751 | struct nfs_setattrres *res, |
| 2752 | struct rpc_cred *cred, |
| 2753 | struct nfs4_state *state) |
| 2754 | { |
| 2755 | struct nfs_server *server = NFS_SERVER(inode); |
| 2756 | struct rpc_message msg = { |
| 2757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2758 | .rpc_argp = arg, |
| 2759 | .rpc_resp = res, |
| 2760 | .rpc_cred = cred, |
| 2761 | }; |
| 2762 | struct rpc_cred *delegation_cred = NULL; |
| 2763 | unsigned long timestamp = jiffies; |
| 2764 | fmode_t fmode; |
| 2765 | bool truncate; |
| 2766 | int status; |
| 2767 | |
| 2768 | nfs_fattr_init(res->fattr); |
| 2769 | |
| 2770 | /* Servers should only apply open mode checks for file size changes */ |
| 2771 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2772 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2773 | |
| 2774 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2775 | /* Use that stateid */ |
| 2776 | } else if (truncate && state != NULL) { |
| 2777 | struct nfs_lockowner lockowner = { |
| 2778 | .l_owner = current->files, |
| 2779 | .l_pid = current->tgid, |
| 2780 | }; |
| 2781 | if (!nfs4_valid_open_stateid(state)) |
| 2782 | return -EBADF; |
| 2783 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2784 | &arg->stateid, &delegation_cred) == -EIO) |
| 2785 | return -EBADF; |
| 2786 | } else |
| 2787 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2788 | if (delegation_cred) |
| 2789 | msg.rpc_cred = delegation_cred; |
| 2790 | |
| 2791 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2792 | |
| 2793 | put_rpccred(delegation_cred); |
| 2794 | if (status == 0 && state != NULL) |
| 2795 | renew_lease(server, timestamp); |
| 2796 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2797 | return status; |
| 2798 | } |
| 2799 | |
| 2800 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2801 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2802 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2803 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2805 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2807 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | .iap = sattr, |
| 2809 | .server = server, |
| 2810 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2811 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | }; |
| 2813 | struct nfs_setattrres res = { |
| 2814 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2815 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | .server = server, |
| 2817 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2818 | struct nfs4_exception exception = { |
| 2819 | .state = state, |
| 2820 | .inode = inode, |
| 2821 | .stateid = &arg.stateid, |
| 2822 | }; |
| 2823 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2825 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2826 | if (ilabel) |
| 2827 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2830 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2831 | switch (err) { |
| 2832 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2833 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2834 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2835 | "applying open mode checks to " |
| 2836 | "a SETATTR that is not " |
| 2837 | "changing file size.\n", |
| 2838 | server->nfs_client->cl_hostname); |
| 2839 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2840 | if (state && !(state->state & FMODE_WRITE)) { |
| 2841 | err = -EBADF; |
| 2842 | if (sattr->ia_valid & ATTR_OPEN) |
| 2843 | err = -EACCES; |
| 2844 | goto out; |
| 2845 | } |
| 2846 | } |
| 2847 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2849 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | return err; |
| 2851 | } |
| 2852 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2853 | static bool |
| 2854 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2855 | { |
| 2856 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2857 | return false; |
| 2858 | |
| 2859 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2860 | } |
| 2861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | struct nfs4_closedata { |
| 2863 | struct inode *inode; |
| 2864 | struct nfs4_state *state; |
| 2865 | struct nfs_closeargs arg; |
| 2866 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2867 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2868 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2869 | bool roc; |
| 2870 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | }; |
| 2872 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2873 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2874 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2875 | struct nfs4_closedata *calldata = data; |
| 2876 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2877 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2878 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2879 | if (calldata->roc) |
| 2880 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2881 | nfs4_put_open_state(calldata->state); |
| 2882 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2883 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2884 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2885 | kfree(calldata); |
| 2886 | } |
| 2887 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2888 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2890 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2893 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2895 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2896 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2897 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2898 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | /* hmm. we are done with the inode, and in the process of freeing |
| 2900 | * the state_owner. we keep this around to process errors |
| 2901 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | switch (task->tk_status) { |
| 2903 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2904 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2905 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2906 | pnfs_roc_set_barrier(state->inode, |
| 2907 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2908 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2909 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2910 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2912 | case -NFS4ERR_OLD_STATEID: |
| 2913 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2915 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2916 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2917 | rpc_restart_call_prepare(task); |
| 2918 | goto out_release; |
| 2919 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2920 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2921 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2923 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2924 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2925 | goto out_release; |
| 2926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2928 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2929 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2930 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2931 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2932 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2933 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2936 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2938 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2939 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2940 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2941 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2942 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2943 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2944 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2945 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2946 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2947 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2948 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2949 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2950 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2951 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2952 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2953 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2954 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2955 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2956 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2957 | if (state->n_rdonly == 0) |
| 2958 | call_close |= is_rdonly; |
| 2959 | else if (is_rdonly) |
| 2960 | calldata->arg.fmode |= FMODE_READ; |
| 2961 | if (state->n_wronly == 0) |
| 2962 | call_close |= is_wronly; |
| 2963 | else if (is_wronly) |
| 2964 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2965 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2966 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2967 | } else if (is_rdwr) |
| 2968 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2969 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2970 | if (!nfs4_valid_open_stateid(state)) |
| 2971 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2972 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2973 | |
| 2974 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2975 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2976 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2977 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2978 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2979 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2980 | nfs_release_seqid(calldata->arg.seqid); |
| 2981 | goto out_wait; |
| 2982 | } |
| 2983 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2984 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2985 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2986 | if (calldata->roc) |
| 2987 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2988 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2989 | calldata->arg.share_access = |
| 2990 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2991 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2992 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2993 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2994 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2995 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2996 | &calldata->arg.seq_args, |
| 2997 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2998 | task) != 0) |
| 2999 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3000 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3001 | return; |
| 3002 | out_no_action: |
| 3003 | task->tk_action = NULL; |
| 3004 | out_wait: |
| 3005 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3008 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3009 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3010 | .rpc_call_done = nfs4_close_done, |
| 3011 | .rpc_release = nfs4_free_closedata, |
| 3012 | }; |
| 3013 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3014 | static bool nfs4_roc(struct inode *inode) |
| 3015 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3016 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3017 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3018 | return pnfs_roc(inode); |
| 3019 | } |
| 3020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | /* |
| 3022 | * It is possible for data to be read/written from a mem-mapped file |
| 3023 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3024 | * This means that we can't safely call nfsv4 close on a file until |
| 3025 | * the inode is cleared. This in turn means that we are not good |
| 3026 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3027 | * share state even when we are done with one of the three share |
| 3028 | * stateid's in the inode. |
| 3029 | * |
| 3030 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3031 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3032 | 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] | 3033 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3034 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3035 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3037 | struct nfs4_state_owner *sp = state->owner; |
| 3038 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3039 | struct rpc_message msg = { |
| 3040 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3041 | .rpc_cred = state->owner->so_cred, |
| 3042 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3043 | struct rpc_task_setup task_setup_data = { |
| 3044 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3045 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3046 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3047 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3048 | .flags = RPC_TASK_ASYNC, |
| 3049 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3050 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3052 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3053 | &task_setup_data.rpc_client, &msg); |
| 3054 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3055 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3057 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3058 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3059 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3061 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3063 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3064 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3065 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3066 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3067 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3068 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3069 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3070 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3071 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3072 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3073 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3074 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3075 | msg.rpc_argp = &calldata->arg; |
| 3076 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3077 | task_setup_data.callback_data = calldata; |
| 3078 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3079 | if (IS_ERR(task)) |
| 3080 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3081 | status = 0; |
| 3082 | if (wait) |
| 3083 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3084 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3085 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3086 | out_free_calldata: |
| 3087 | kfree(calldata); |
| 3088 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3089 | nfs4_put_open_state(state); |
| 3090 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3091 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3094 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3095 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3096 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3099 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3100 | |
| 3101 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3103 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3104 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3105 | |
| 3106 | nfs4_label_release_security(label); |
| 3107 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3108 | if (IS_ERR(state)) |
| 3109 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3110 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3113 | 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] | 3114 | { |
| 3115 | if (ctx->state == NULL) |
| 3116 | return; |
| 3117 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3118 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3119 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3120 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3123 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3124 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3125 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3128 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3129 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3130 | struct nfs4_server_caps_arg args = { |
| 3131 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3132 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3133 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | struct nfs4_server_caps_res res = {}; |
| 3135 | struct rpc_message msg = { |
| 3136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3137 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | .rpc_resp = &res, |
| 3139 | }; |
| 3140 | int status; |
| 3141 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3142 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3143 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3144 | FATTR4_WORD0_LINK_SUPPORT | |
| 3145 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3146 | FATTR4_WORD0_ACLSUPPORT; |
| 3147 | if (minorversion) |
| 3148 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3149 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3150 | 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] | 3151 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3152 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3153 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3154 | case 0: |
| 3155 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3156 | res.attr_bitmask[2] = 0; |
| 3157 | break; |
| 3158 | case 1: |
| 3159 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3160 | break; |
| 3161 | case 2: |
| 3162 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3165 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3166 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3167 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3168 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3169 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3170 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3171 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3172 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | server->caps |= NFS_CAP_ACLS; |
| 3174 | if (res.has_links != 0) |
| 3175 | server->caps |= NFS_CAP_HARDLINKS; |
| 3176 | if (res.has_symlinks != 0) |
| 3177 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3178 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3179 | server->caps |= NFS_CAP_FILEID; |
| 3180 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3181 | server->caps |= NFS_CAP_MODE; |
| 3182 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3183 | server->caps |= NFS_CAP_NLINK; |
| 3184 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3185 | server->caps |= NFS_CAP_OWNER; |
| 3186 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3187 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3188 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3189 | server->caps |= NFS_CAP_ATIME; |
| 3190 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3191 | server->caps |= NFS_CAP_CTIME; |
| 3192 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3193 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3194 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3195 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3196 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3197 | #endif |
| 3198 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3199 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3200 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3201 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3202 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3203 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3204 | 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] | 3205 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3206 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3207 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3209 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | return status; |
| 3213 | } |
| 3214 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3215 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | { |
| 3217 | struct nfs4_exception exception = { }; |
| 3218 | int err; |
| 3219 | do { |
| 3220 | err = nfs4_handle_exception(server, |
| 3221 | _nfs4_server_capabilities(server, fhandle), |
| 3222 | &exception); |
| 3223 | } while (exception.retry); |
| 3224 | return err; |
| 3225 | } |
| 3226 | |
| 3227 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3228 | struct nfs_fsinfo *info) |
| 3229 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3230 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3232 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | }; |
| 3234 | struct nfs4_lookup_res res = { |
| 3235 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3236 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | .fh = fhandle, |
| 3238 | }; |
| 3239 | struct rpc_message msg = { |
| 3240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3241 | .rpc_argp = &args, |
| 3242 | .rpc_resp = &res, |
| 3243 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3244 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3245 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3246 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3247 | /* |
| 3248 | * Process the label in the upcoming getfattr |
| 3249 | */ |
| 3250 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3251 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3252 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3253 | 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] | 3254 | } |
| 3255 | |
| 3256 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3257 | struct nfs_fsinfo *info) |
| 3258 | { |
| 3259 | struct nfs4_exception exception = { }; |
| 3260 | int err; |
| 3261 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3262 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3263 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3264 | switch (err) { |
| 3265 | case 0: |
| 3266 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3267 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3268 | default: |
| 3269 | err = nfs4_handle_exception(server, err, &exception); |
| 3270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3272 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | return err; |
| 3274 | } |
| 3275 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3276 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3277 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3278 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3279 | struct rpc_auth_create_args auth_args = { |
| 3280 | .pseudoflavor = flavor, |
| 3281 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3282 | struct rpc_auth *auth; |
| 3283 | int ret; |
| 3284 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3285 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3286 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3287 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3288 | goto out; |
| 3289 | } |
| 3290 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3291 | out: |
| 3292 | return ret; |
| 3293 | } |
| 3294 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3295 | /* |
| 3296 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3297 | * |
| 3298 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3299 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3300 | * |
| 3301 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3302 | * negative errno value. |
| 3303 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3304 | 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] | 3305 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3307 | /* Per 3530bis 15.33.5 */ |
| 3308 | static const rpc_authflavor_t flav_array[] = { |
| 3309 | RPC_AUTH_GSS_KRB5P, |
| 3310 | RPC_AUTH_GSS_KRB5I, |
| 3311 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3312 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3313 | RPC_AUTH_NULL, |
| 3314 | }; |
| 3315 | int status = -EPERM; |
| 3316 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3318 | if (server->auth_info.flavor_len > 0) { |
| 3319 | /* try each flavor specified by user */ |
| 3320 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3321 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3322 | server->auth_info.flavors[i]); |
| 3323 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3324 | continue; |
| 3325 | break; |
| 3326 | } |
| 3327 | } else { |
| 3328 | /* no flavors specified by user, try default list */ |
| 3329 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3330 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3331 | flav_array[i]); |
| 3332 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3333 | continue; |
| 3334 | break; |
| 3335 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3336 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3337 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3338 | /* |
| 3339 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3340 | * to access the mount. It could also mean that we tried to mount |
| 3341 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3342 | * existing mount programs don't handle -EACCES very well so it should |
| 3343 | * be mapped to -EPERM instead. |
| 3344 | */ |
| 3345 | if (status == -EACCES) |
| 3346 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3347 | return status; |
| 3348 | } |
| 3349 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3350 | /** |
| 3351 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3352 | * @server: initialized nfs_server handle |
| 3353 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3354 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3355 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3356 | * |
| 3357 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3358 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3359 | 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] | 3360 | struct nfs_fsinfo *info, |
| 3361 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3362 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3363 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3364 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3365 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3366 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3367 | |
| 3368 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3369 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3370 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | if (status == 0) |
| 3373 | status = nfs4_server_capabilities(server, fhandle); |
| 3374 | if (status == 0) |
| 3375 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3376 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3377 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3380 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3381 | struct nfs_fsinfo *info) |
| 3382 | { |
| 3383 | int error; |
| 3384 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3385 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3386 | |
| 3387 | error = nfs4_server_capabilities(server, mntfh); |
| 3388 | if (error < 0) { |
| 3389 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3390 | return error; |
| 3391 | } |
| 3392 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3393 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3394 | if (IS_ERR(label)) |
| 3395 | return PTR_ERR(label); |
| 3396 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3397 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3398 | if (error < 0) { |
| 3399 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3400 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3404 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3405 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3406 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3407 | err_free_label: |
| 3408 | nfs4_label_free(label); |
| 3409 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3410 | return error; |
| 3411 | } |
| 3412 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3413 | /* |
| 3414 | * Get locations and (maybe) other attributes of a referral. |
| 3415 | * Note that we'll actually follow the referral later when |
| 3416 | * we detect fsid mismatch in inode revalidation |
| 3417 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3418 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3419 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3420 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3421 | { |
| 3422 | int status = -ENOMEM; |
| 3423 | struct page *page = NULL; |
| 3424 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3425 | |
| 3426 | page = alloc_page(GFP_KERNEL); |
| 3427 | if (page == NULL) |
| 3428 | goto out; |
| 3429 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3430 | if (locations == NULL) |
| 3431 | goto out; |
| 3432 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3433 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3434 | if (status != 0) |
| 3435 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3436 | |
| 3437 | /* |
| 3438 | * If the fsid didn't change, this is a migration event, not a |
| 3439 | * referral. Cause us to drop into the exception handler, which |
| 3440 | * will kick off migration recovery. |
| 3441 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3442 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3443 | dprintk("%s: server did not return a different fsid for" |
| 3444 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3445 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3446 | goto out; |
| 3447 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3448 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3449 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3450 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3451 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3452 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3453 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3454 | out: |
| 3455 | if (page) |
| 3456 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3457 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3458 | return status; |
| 3459 | } |
| 3460 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3461 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3462 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | { |
| 3464 | struct nfs4_getattr_arg args = { |
| 3465 | .fh = fhandle, |
| 3466 | .bitmask = server->attr_bitmask, |
| 3467 | }; |
| 3468 | struct nfs4_getattr_res res = { |
| 3469 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3470 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | .server = server, |
| 3472 | }; |
| 3473 | struct rpc_message msg = { |
| 3474 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3475 | .rpc_argp = &args, |
| 3476 | .rpc_resp = &res, |
| 3477 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3478 | |
| 3479 | args.bitmask = nfs4_bitmask(server, label); |
| 3480 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3481 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3482 | 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] | 3483 | } |
| 3484 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3485 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3486 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | { |
| 3488 | struct nfs4_exception exception = { }; |
| 3489 | int err; |
| 3490 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3491 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3492 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3493 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | &exception); |
| 3495 | } while (exception.retry); |
| 3496 | return err; |
| 3497 | } |
| 3498 | |
| 3499 | /* |
| 3500 | * The file is not closed if it is opened due to the a request to change |
| 3501 | * the size of the file. The open call will not be needed once the |
| 3502 | * VFS layer lookup-intents are implemented. |
| 3503 | * |
| 3504 | * Close is called when the inode is destroyed. |
| 3505 | * If we haven't opened the file for O_WRONLY, we |
| 3506 | * need to in the size_change case to obtain a stateid. |
| 3507 | * |
| 3508 | * Got race? |
| 3509 | * Because OPEN is always done by name in nfsv4, it is |
| 3510 | * possible that we opened a different file by the same |
| 3511 | * name. We can recognize this race condition, but we |
| 3512 | * can't do anything about it besides returning an error. |
| 3513 | * |
| 3514 | * This will be fixed with VFS changes (lookup-intent). |
| 3515 | */ |
| 3516 | static int |
| 3517 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3518 | struct iattr *sattr) |
| 3519 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3520 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3521 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3522 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3523 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | int status; |
| 3525 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3526 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3527 | sattr->ia_valid & ATTR_SIZE && |
| 3528 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3529 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3530 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3531 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3533 | /* Deal with open(O_TRUNC) */ |
| 3534 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3535 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3536 | |
| 3537 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3538 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3539 | return 0; |
| 3540 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3541 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3542 | if (sattr->ia_valid & ATTR_FILE) { |
| 3543 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3544 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3545 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3546 | if (ctx) { |
| 3547 | cred = ctx->cred; |
| 3548 | state = ctx->state; |
| 3549 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3550 | } |
| 3551 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3552 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3553 | if (IS_ERR(label)) |
| 3554 | return PTR_ERR(label); |
| 3555 | |
| 3556 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3557 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3558 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3559 | nfs_setsecurity(inode, fattr, label); |
| 3560 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3561 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | return status; |
| 3563 | } |
| 3564 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3565 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3566 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3567 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3568 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3569 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3570 | int status; |
| 3571 | struct nfs4_lookup_arg args = { |
| 3572 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3573 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3574 | .name = name, |
| 3575 | }; |
| 3576 | struct nfs4_lookup_res res = { |
| 3577 | .server = server, |
| 3578 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3579 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3580 | .fh = fhandle, |
| 3581 | }; |
| 3582 | struct rpc_message msg = { |
| 3583 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3584 | .rpc_argp = &args, |
| 3585 | .rpc_resp = &res, |
| 3586 | }; |
| 3587 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3588 | args.bitmask = nfs4_bitmask(server, label); |
| 3589 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3590 | nfs_fattr_init(fattr); |
| 3591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3593 | 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] | 3594 | dprintk("NFS reply lookup: %d\n", status); |
| 3595 | return status; |
| 3596 | } |
| 3597 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3598 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3599 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3600 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3601 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3602 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3603 | fattr->nlink = 2; |
| 3604 | } |
| 3605 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3606 | 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] | 3607 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3609 | { |
| 3610 | struct nfs4_exception exception = { }; |
| 3611 | struct rpc_clnt *client = *clnt; |
| 3612 | int err; |
| 3613 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3614 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3615 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3616 | switch (err) { |
| 3617 | case -NFS4ERR_BADNAME: |
| 3618 | err = -ENOENT; |
| 3619 | goto out; |
| 3620 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3621 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3622 | if (err == -NFS4ERR_MOVED) |
| 3623 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3624 | goto out; |
| 3625 | case -NFS4ERR_WRONGSEC: |
| 3626 | err = -EPERM; |
| 3627 | if (client != *clnt) |
| 3628 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3629 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3630 | if (IS_ERR(client)) |
| 3631 | return PTR_ERR(client); |
| 3632 | |
| 3633 | exception.retry = 1; |
| 3634 | break; |
| 3635 | default: |
| 3636 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3637 | } |
| 3638 | } while (exception.retry); |
| 3639 | |
| 3640 | out: |
| 3641 | if (err == 0) |
| 3642 | *clnt = client; |
| 3643 | else if (client != *clnt) |
| 3644 | rpc_shutdown_client(client); |
| 3645 | |
| 3646 | return err; |
| 3647 | } |
| 3648 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3649 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3650 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3651 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3653 | int status; |
| 3654 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3655 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3656 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3657 | if (client != NFS_CLIENT(dir)) { |
| 3658 | rpc_shutdown_client(client); |
| 3659 | nfs_fixup_secinfo_attributes(fattr); |
| 3660 | } |
| 3661 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3664 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3665 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3666 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3667 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3668 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3669 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3670 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3671 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3672 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3673 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3674 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3678 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3679 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | struct nfs4_accessargs args = { |
| 3681 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3682 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3684 | struct nfs4_accessres res = { |
| 3685 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3686 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | struct rpc_message msg = { |
| 3688 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3689 | .rpc_argp = &args, |
| 3690 | .rpc_resp = &res, |
| 3691 | .rpc_cred = entry->cred, |
| 3692 | }; |
| 3693 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3694 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | |
| 3696 | /* |
| 3697 | * Determine which access bits we want to ask for... |
| 3698 | */ |
| 3699 | if (mode & MAY_READ) |
| 3700 | args.access |= NFS4_ACCESS_READ; |
| 3701 | if (S_ISDIR(inode->i_mode)) { |
| 3702 | if (mode & MAY_WRITE) |
| 3703 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3704 | if (mode & MAY_EXEC) |
| 3705 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3706 | } else { |
| 3707 | if (mode & MAY_WRITE) |
| 3708 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3709 | if (mode & MAY_EXEC) |
| 3710 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3711 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3712 | |
| 3713 | res.fattr = nfs_alloc_fattr(); |
| 3714 | if (res.fattr == NULL) |
| 3715 | return -ENOMEM; |
| 3716 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3717 | 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] | 3718 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3719 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3720 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3722 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | return status; |
| 3724 | } |
| 3725 | |
| 3726 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3727 | { |
| 3728 | struct nfs4_exception exception = { }; |
| 3729 | int err; |
| 3730 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3731 | err = _nfs4_proc_access(inode, entry); |
| 3732 | trace_nfs4_access(inode, err); |
| 3733 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | &exception); |
| 3735 | } while (exception.retry); |
| 3736 | return err; |
| 3737 | } |
| 3738 | |
| 3739 | /* |
| 3740 | * TODO: For the time being, we don't try to get any attributes |
| 3741 | * along with any of the zero-copy operations READ, READDIR, |
| 3742 | * READLINK, WRITE. |
| 3743 | * |
| 3744 | * In the case of the first three, we want to put the GETATTR |
| 3745 | * after the read-type operation -- this is because it is hard |
| 3746 | * to predict the length of a GETATTR response in v4, and thus |
| 3747 | * align the READ data correctly. This means that the GETATTR |
| 3748 | * may end up partially falling into the page cache, and we should |
| 3749 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3750 | * To do this efficiently, we need to know the total length |
| 3751 | * of data received, which doesn't seem to be available outside |
| 3752 | * of the RPC layer. |
| 3753 | * |
| 3754 | * In the case of WRITE, we also want to put the GETATTR after |
| 3755 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3756 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | * |
| 3758 | * Both of these changes to the XDR layer would in fact be quite |
| 3759 | * minor, but I decided to leave them for a subsequent patch. |
| 3760 | */ |
| 3761 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3762 | unsigned int pgbase, unsigned int pglen) |
| 3763 | { |
| 3764 | struct nfs4_readlink args = { |
| 3765 | .fh = NFS_FH(inode), |
| 3766 | .pgbase = pgbase, |
| 3767 | .pglen = pglen, |
| 3768 | .pages = &page, |
| 3769 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3770 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | struct rpc_message msg = { |
| 3772 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3773 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3774 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | }; |
| 3776 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3777 | 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] | 3778 | } |
| 3779 | |
| 3780 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3781 | unsigned int pgbase, unsigned int pglen) |
| 3782 | { |
| 3783 | struct nfs4_exception exception = { }; |
| 3784 | int err; |
| 3785 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3786 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3787 | trace_nfs4_readlink(inode, err); |
| 3788 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | &exception); |
| 3790 | } while (exception.retry); |
| 3791 | return err; |
| 3792 | } |
| 3793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3795 | * 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] | 3796 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | static int |
| 3798 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3799 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3801 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3802 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | int status = 0; |
| 3805 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3806 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3807 | if (IS_ERR(ctx)) |
| 3808 | return PTR_ERR(ctx); |
| 3809 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3810 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3811 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3812 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3813 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | if (IS_ERR(state)) { |
| 3815 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3816 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3819 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3820 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | return status; |
| 3822 | } |
| 3823 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3824 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3826 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3827 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3829 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3831 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3832 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3833 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3836 | .rpc_argp = &args, |
| 3837 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3839 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3840 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3841 | 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] | 3842 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3843 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | return status; |
| 3845 | } |
| 3846 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3847 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | { |
| 3849 | struct nfs4_exception exception = { }; |
| 3850 | int err; |
| 3851 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3852 | err = _nfs4_proc_remove(dir, name); |
| 3853 | trace_nfs4_remove(dir, name, err); |
| 3854 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | &exception); |
| 3856 | } while (exception.retry); |
| 3857 | return err; |
| 3858 | } |
| 3859 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3860 | 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] | 3861 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3862 | struct nfs_server *server = NFS_SERVER(dir); |
| 3863 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3864 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3866 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3868 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3869 | |
| 3870 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | } |
| 3872 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3873 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3874 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3875 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3876 | &data->args.seq_args, |
| 3877 | &data->res.seq_res, |
| 3878 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3881 | 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] | 3882 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3883 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3884 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3885 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3886 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3887 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3888 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3889 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3890 | return 0; |
| 3891 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3892 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | } |
| 3894 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3895 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3896 | { |
| 3897 | struct nfs_server *server = NFS_SERVER(dir); |
| 3898 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3899 | struct nfs_renameres *res = msg->rpc_resp; |
| 3900 | |
| 3901 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3902 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3903 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3904 | } |
| 3905 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3906 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3907 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3908 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3909 | &data->args.seq_args, |
| 3910 | &data->res.seq_res, |
| 3911 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3915 | struct inode *new_dir) |
| 3916 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3917 | struct nfs_renamedata *data = task->tk_calldata; |
| 3918 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3919 | |
| 3920 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3921 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3922 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3923 | return 0; |
| 3924 | |
| 3925 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3926 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3927 | return 1; |
| 3928 | } |
| 3929 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3930 | 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] | 3931 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3932 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | struct nfs4_link_arg arg = { |
| 3934 | .fh = NFS_FH(inode), |
| 3935 | .dir_fh = NFS_FH(dir), |
| 3936 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3937 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3939 | struct nfs4_link_res res = { |
| 3940 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3941 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3942 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | struct rpc_message msg = { |
| 3944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3945 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3946 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3948 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3950 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3951 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3952 | goto out; |
| 3953 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3954 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3955 | if (IS_ERR(res.label)) { |
| 3956 | status = PTR_ERR(res.label); |
| 3957 | goto out; |
| 3958 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3959 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3960 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3961 | 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] | 3962 | if (!status) { |
| 3963 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3964 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3965 | if (!status) |
| 3966 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3967 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3968 | |
| 3969 | |
| 3970 | nfs4_label_free(res.label); |
| 3971 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3972 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3973 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | return status; |
| 3975 | } |
| 3976 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3977 | 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] | 3978 | { |
| 3979 | struct nfs4_exception exception = { }; |
| 3980 | int err; |
| 3981 | do { |
| 3982 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3983 | _nfs4_proc_link(inode, dir, name), |
| 3984 | &exception); |
| 3985 | } while (exception.retry); |
| 3986 | return err; |
| 3987 | } |
| 3988 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3989 | struct nfs4_createdata { |
| 3990 | struct rpc_message msg; |
| 3991 | struct nfs4_create_arg arg; |
| 3992 | struct nfs4_create_res res; |
| 3993 | struct nfs_fh fh; |
| 3994 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3995 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3996 | }; |
| 3997 | |
| 3998 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3999 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4000 | { |
| 4001 | struct nfs4_createdata *data; |
| 4002 | |
| 4003 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4004 | if (data != NULL) { |
| 4005 | struct nfs_server *server = NFS_SERVER(dir); |
| 4006 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4007 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4008 | if (IS_ERR(data->label)) |
| 4009 | goto out_free; |
| 4010 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4011 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4012 | data->msg.rpc_argp = &data->arg; |
| 4013 | data->msg.rpc_resp = &data->res; |
| 4014 | data->arg.dir_fh = NFS_FH(dir); |
| 4015 | data->arg.server = server; |
| 4016 | data->arg.name = name; |
| 4017 | data->arg.attrs = sattr; |
| 4018 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4019 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4020 | data->res.server = server; |
| 4021 | data->res.fh = &data->fh; |
| 4022 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4023 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4024 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4025 | } |
| 4026 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4027 | out_free: |
| 4028 | kfree(data); |
| 4029 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4033 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4034 | 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] | 4035 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4036 | if (status == 0) { |
| 4037 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4038 | 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] | 4039 | } |
| 4040 | return status; |
| 4041 | } |
| 4042 | |
| 4043 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4044 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4045 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4046 | kfree(data); |
| 4047 | } |
| 4048 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4049 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4050 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4051 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4053 | struct nfs4_createdata *data; |
| 4054 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4056 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4057 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4058 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4059 | status = -ENOMEM; |
| 4060 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4061 | if (data == NULL) |
| 4062 | goto out; |
| 4063 | |
| 4064 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4065 | data->arg.u.symlink.pages = &page; |
| 4066 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4067 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4069 | status = nfs4_do_create(dir, dentry, data); |
| 4070 | |
| 4071 | nfs4_free_createdata(data); |
| 4072 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | return status; |
| 4074 | } |
| 4075 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4076 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4077 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | { |
| 4079 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4080 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4082 | |
| 4083 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4086 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4087 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4088 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | &exception); |
| 4090 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4091 | |
| 4092 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | return err; |
| 4094 | } |
| 4095 | |
| 4096 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4097 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4099 | struct nfs4_createdata *data; |
| 4100 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4102 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4103 | if (data == NULL) |
| 4104 | goto out; |
| 4105 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4106 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4107 | status = nfs4_do_create(dir, dentry, data); |
| 4108 | |
| 4109 | nfs4_free_createdata(data); |
| 4110 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | return status; |
| 4112 | } |
| 4113 | |
| 4114 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4115 | struct iattr *sattr) |
| 4116 | { |
| 4117 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4118 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4120 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4121 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4122 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4123 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4125 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4126 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4127 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | &exception); |
| 4129 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4130 | nfs4_label_release_security(label); |
| 4131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | return err; |
| 4133 | } |
| 4134 | |
| 4135 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4136 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4138 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | struct nfs4_readdir_arg args = { |
| 4140 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4141 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | .pgbase = 0, |
| 4143 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4144 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4145 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | }; |
| 4147 | struct nfs4_readdir_res res; |
| 4148 | struct rpc_message msg = { |
| 4149 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4150 | .rpc_argp = &args, |
| 4151 | .rpc_resp = &res, |
| 4152 | .rpc_cred = cred, |
| 4153 | }; |
| 4154 | int status; |
| 4155 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4156 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4157 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4158 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4159 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4161 | 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] | 4162 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4163 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4164 | status += args.pgbase; |
| 4165 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4166 | |
| 4167 | nfs_invalidate_atime(dir); |
| 4168 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4169 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | return status; |
| 4171 | } |
| 4172 | |
| 4173 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4174 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | { |
| 4176 | struct nfs4_exception exception = { }; |
| 4177 | int err; |
| 4178 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4179 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4180 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4181 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4182 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | &exception); |
| 4184 | } while (exception.retry); |
| 4185 | return err; |
| 4186 | } |
| 4187 | |
| 4188 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4189 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4191 | struct nfs4_createdata *data; |
| 4192 | int mode = sattr->ia_mode; |
| 4193 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4195 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4196 | if (data == NULL) |
| 4197 | goto out; |
| 4198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4200 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4202 | data->arg.ftype = NF4BLK; |
| 4203 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4204 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | } |
| 4206 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4207 | data->arg.ftype = NF4CHR; |
| 4208 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4209 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4210 | } else if (!S_ISSOCK(mode)) { |
| 4211 | status = -EINVAL; |
| 4212 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4214 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4215 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4216 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4217 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4218 | nfs4_free_createdata(data); |
| 4219 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | return status; |
| 4221 | } |
| 4222 | |
| 4223 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4224 | struct iattr *sattr, dev_t rdev) |
| 4225 | { |
| 4226 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4227 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4229 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4230 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4231 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4232 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4234 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4235 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4236 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | &exception); |
| 4238 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4239 | |
| 4240 | nfs4_label_release_security(label); |
| 4241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | return err; |
| 4243 | } |
| 4244 | |
| 4245 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4246 | struct nfs_fsstat *fsstat) |
| 4247 | { |
| 4248 | struct nfs4_statfs_arg args = { |
| 4249 | .fh = fhandle, |
| 4250 | .bitmask = server->attr_bitmask, |
| 4251 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4252 | struct nfs4_statfs_res res = { |
| 4253 | .fsstat = fsstat, |
| 4254 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | struct rpc_message msg = { |
| 4256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4257 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4258 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | }; |
| 4260 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4261 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4262 | 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] | 4263 | } |
| 4264 | |
| 4265 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4266 | { |
| 4267 | struct nfs4_exception exception = { }; |
| 4268 | int err; |
| 4269 | do { |
| 4270 | err = nfs4_handle_exception(server, |
| 4271 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4272 | &exception); |
| 4273 | } while (exception.retry); |
| 4274 | return err; |
| 4275 | } |
| 4276 | |
| 4277 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4278 | struct nfs_fsinfo *fsinfo) |
| 4279 | { |
| 4280 | struct nfs4_fsinfo_arg args = { |
| 4281 | .fh = fhandle, |
| 4282 | .bitmask = server->attr_bitmask, |
| 4283 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4284 | struct nfs4_fsinfo_res res = { |
| 4285 | .fsinfo = fsinfo, |
| 4286 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | struct rpc_message msg = { |
| 4288 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4289 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4290 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | }; |
| 4292 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4293 | 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] | 4294 | } |
| 4295 | |
| 4296 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4297 | { |
| 4298 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4299 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | int err; |
| 4301 | |
| 4302 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4303 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4304 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4305 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4306 | nfs4_set_lease_period(server->nfs_client, |
| 4307 | fsinfo->lease_time * HZ, |
| 4308 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4309 | break; |
| 4310 | } |
| 4311 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | } while (exception.retry); |
| 4313 | return err; |
| 4314 | } |
| 4315 | |
| 4316 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4317 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4318 | int error; |
| 4319 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4320 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4321 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4322 | if (error == 0) { |
| 4323 | /* block layout checks this! */ |
| 4324 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4325 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4326 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4327 | |
| 4328 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4332 | struct nfs_pathconf *pathconf) |
| 4333 | { |
| 4334 | struct nfs4_pathconf_arg args = { |
| 4335 | .fh = fhandle, |
| 4336 | .bitmask = server->attr_bitmask, |
| 4337 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4338 | struct nfs4_pathconf_res res = { |
| 4339 | .pathconf = pathconf, |
| 4340 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | struct rpc_message msg = { |
| 4342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4343 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4344 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | }; |
| 4346 | |
| 4347 | /* None of the pathconf attributes are mandatory to implement */ |
| 4348 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4349 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4350 | return 0; |
| 4351 | } |
| 4352 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4353 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4354 | 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] | 4355 | } |
| 4356 | |
| 4357 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4358 | struct nfs_pathconf *pathconf) |
| 4359 | { |
| 4360 | struct nfs4_exception exception = { }; |
| 4361 | int err; |
| 4362 | |
| 4363 | do { |
| 4364 | err = nfs4_handle_exception(server, |
| 4365 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4366 | &exception); |
| 4367 | } while (exception.retry); |
| 4368 | return err; |
| 4369 | } |
| 4370 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4371 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4372 | const struct nfs_open_context *ctx, |
| 4373 | const struct nfs_lock_context *l_ctx, |
| 4374 | fmode_t fmode) |
| 4375 | { |
| 4376 | const struct nfs_lockowner *lockowner = NULL; |
| 4377 | |
| 4378 | if (l_ctx != NULL) |
| 4379 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4380 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4381 | } |
| 4382 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4383 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4384 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4385 | const struct nfs_open_context *ctx, |
| 4386 | const struct nfs_lock_context *l_ctx, |
| 4387 | fmode_t fmode) |
| 4388 | { |
| 4389 | nfs4_stateid current_stateid; |
| 4390 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4391 | /* If the current stateid represents a lost lock, then exit */ |
| 4392 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4393 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4394 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4395 | } |
| 4396 | |
| 4397 | static bool nfs4_error_stateid_expired(int err) |
| 4398 | { |
| 4399 | switch (err) { |
| 4400 | case -NFS4ERR_DELEG_REVOKED: |
| 4401 | case -NFS4ERR_ADMIN_REVOKED: |
| 4402 | case -NFS4ERR_BAD_STATEID: |
| 4403 | case -NFS4ERR_STALE_STATEID: |
| 4404 | case -NFS4ERR_OLD_STATEID: |
| 4405 | case -NFS4ERR_OPENMODE: |
| 4406 | case -NFS4ERR_EXPIRED: |
| 4407 | return true; |
| 4408 | } |
| 4409 | return false; |
| 4410 | } |
| 4411 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4412 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4413 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4414 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4415 | } |
| 4416 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4417 | 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] | 4418 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4419 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4421 | trace_nfs4_read(hdr, task->tk_status); |
| 4422 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4423 | hdr->args.context->state, |
| 4424 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4425 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4426 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4428 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4429 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4431 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4432 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4435 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4436 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4437 | { |
| 4438 | |
| 4439 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4440 | nfs4_stateid_is_current(&args->stateid, |
| 4441 | args->context, |
| 4442 | args->lock_context, |
| 4443 | FMODE_READ)) |
| 4444 | return false; |
| 4445 | rpc_restart_call_prepare(task); |
| 4446 | return true; |
| 4447 | } |
| 4448 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4449 | 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] | 4450 | { |
| 4451 | |
| 4452 | dprintk("--> %s\n", __func__); |
| 4453 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4454 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4455 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4456 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4457 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4458 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4459 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4462 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4463 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4465 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4466 | if (!hdr->pgio_done_cb) |
| 4467 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4468 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4469 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | } |
| 4471 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4472 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4473 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4474 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4475 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4476 | &hdr->args.seq_args, |
| 4477 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4478 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4479 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4480 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4481 | hdr->args.lock_context, |
| 4482 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4483 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4484 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4485 | return -EIO; |
| 4486 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4489 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4490 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4492 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4493 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4494 | trace_nfs4_write(hdr, task->tk_status); |
| 4495 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4496 | hdr->args.context->state, |
| 4497 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4498 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4499 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4501 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4502 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4503 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4504 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4505 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4508 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4509 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4510 | { |
| 4511 | |
| 4512 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4513 | nfs4_stateid_is_current(&args->stateid, |
| 4514 | args->context, |
| 4515 | args->lock_context, |
| 4516 | FMODE_WRITE)) |
| 4517 | return false; |
| 4518 | rpc_restart_call_prepare(task); |
| 4519 | return true; |
| 4520 | } |
| 4521 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4522 | 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] | 4523 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4524 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4525 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4526 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4527 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4528 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4529 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4532 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4533 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4534 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4535 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4536 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4537 | return false; |
| 4538 | /* Otherwise, request attributes if and only if we don't hold |
| 4539 | * a delegation |
| 4540 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4541 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4542 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4543 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4544 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4545 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4547 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4548 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4549 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4550 | hdr->args.bitmask = NULL; |
| 4551 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4552 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4553 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4554 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4555 | if (!hdr->pgio_done_cb) |
| 4556 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4557 | hdr->res.server = server; |
| 4558 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4560 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4561 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4564 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4565 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4566 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4567 | &data->args.seq_args, |
| 4568 | &data->res.seq_res, |
| 4569 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4572 | 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] | 4573 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4575 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4576 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4577 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4578 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4579 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4580 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4582 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4585 | 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] | 4586 | { |
| 4587 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4588 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4589 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4592 | 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] | 4593 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4594 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4595 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4596 | if (data->commit_done_cb == NULL) |
| 4597 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4598 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4599 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4600 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4603 | struct nfs4_renewdata { |
| 4604 | struct nfs_client *client; |
| 4605 | unsigned long timestamp; |
| 4606 | }; |
| 4607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | /* |
| 4609 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4610 | * standalone procedure for queueing an asynchronous RENEW. |
| 4611 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4612 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4613 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4614 | struct nfs4_renewdata *data = calldata; |
| 4615 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4616 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4617 | if (atomic_read(&clp->cl_count) > 1) |
| 4618 | nfs4_schedule_state_renewal(clp); |
| 4619 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4620 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4621 | } |
| 4622 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4623 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4625 | struct nfs4_renewdata *data = calldata; |
| 4626 | struct nfs_client *clp = data->client; |
| 4627 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4629 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4630 | switch (task->tk_status) { |
| 4631 | case 0: |
| 4632 | break; |
| 4633 | case -NFS4ERR_LEASE_MOVED: |
| 4634 | nfs4_schedule_lease_moved_recovery(clp); |
| 4635 | break; |
| 4636 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4637 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4638 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4639 | return; |
| 4640 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4641 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4642 | return; |
| 4643 | } |
| 4644 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4646 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4649 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4650 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4651 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4652 | }; |
| 4653 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4654 | 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] | 4655 | { |
| 4656 | struct rpc_message msg = { |
| 4657 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4658 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4659 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4661 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4663 | if (renew_flags == 0) |
| 4664 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4665 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4666 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4667 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4668 | if (data == NULL) |
| 4669 | return -ENOMEM; |
| 4670 | data->client = clp; |
| 4671 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4672 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4673 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4676 | 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] | 4677 | { |
| 4678 | struct rpc_message msg = { |
| 4679 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4680 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4681 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | }; |
| 4683 | unsigned long now = jiffies; |
| 4684 | int status; |
| 4685 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4686 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | if (status < 0) |
| 4688 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4689 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | return 0; |
| 4691 | } |
| 4692 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4693 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4694 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4695 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4698 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4699 | * 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] | 4700 | * the stack. |
| 4701 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4702 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4703 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4704 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4705 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4706 | { |
| 4707 | struct page *newpage, **spages; |
| 4708 | int rc = 0; |
| 4709 | size_t len; |
| 4710 | spages = pages; |
| 4711 | |
| 4712 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4713 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4714 | newpage = alloc_page(GFP_KERNEL); |
| 4715 | |
| 4716 | if (newpage == NULL) |
| 4717 | goto unwind; |
| 4718 | memcpy(page_address(newpage), buf, len); |
| 4719 | buf += len; |
| 4720 | buflen -= len; |
| 4721 | *pages++ = newpage; |
| 4722 | rc++; |
| 4723 | } while (buflen != 0); |
| 4724 | |
| 4725 | return rc; |
| 4726 | |
| 4727 | unwind: |
| 4728 | for(; rc > 0; rc--) |
| 4729 | __free_page(spages[rc-1]); |
| 4730 | return -ENOMEM; |
| 4731 | } |
| 4732 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4733 | struct nfs4_cached_acl { |
| 4734 | int cached; |
| 4735 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4736 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4737 | }; |
| 4738 | |
| 4739 | 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] | 4740 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4741 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4742 | |
| 4743 | spin_lock(&inode->i_lock); |
| 4744 | kfree(nfsi->nfs4_acl); |
| 4745 | nfsi->nfs4_acl = acl; |
| 4746 | spin_unlock(&inode->i_lock); |
| 4747 | } |
| 4748 | |
| 4749 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4750 | { |
| 4751 | nfs4_set_cached_acl(inode, NULL); |
| 4752 | } |
| 4753 | |
| 4754 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4755 | { |
| 4756 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4757 | struct nfs4_cached_acl *acl; |
| 4758 | int ret = -ENOENT; |
| 4759 | |
| 4760 | spin_lock(&inode->i_lock); |
| 4761 | acl = nfsi->nfs4_acl; |
| 4762 | if (acl == NULL) |
| 4763 | goto out; |
| 4764 | if (buf == NULL) /* user is just asking for length */ |
| 4765 | goto out_len; |
| 4766 | if (acl->cached == 0) |
| 4767 | goto out; |
| 4768 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4769 | if (acl->len > buflen) |
| 4770 | goto out; |
| 4771 | memcpy(buf, acl->data, acl->len); |
| 4772 | out_len: |
| 4773 | ret = acl->len; |
| 4774 | out: |
| 4775 | spin_unlock(&inode->i_lock); |
| 4776 | return ret; |
| 4777 | } |
| 4778 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4779 | 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] | 4780 | { |
| 4781 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4782 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4783 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4784 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4785 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4786 | if (acl == NULL) |
| 4787 | goto out; |
| 4788 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4789 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4790 | } else { |
| 4791 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4792 | if (acl == NULL) |
| 4793 | goto out; |
| 4794 | acl->cached = 0; |
| 4795 | } |
| 4796 | acl->len = acl_len; |
| 4797 | out: |
| 4798 | nfs4_set_cached_acl(inode, acl); |
| 4799 | } |
| 4800 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4801 | /* |
| 4802 | * The getxattr API returns the required buffer length when called with a |
| 4803 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4804 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4805 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4806 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4807 | * the cache. If not so, we throw away the page, and cache the required |
| 4808 | * length. The next getxattr call will then produce another round trip to |
| 4809 | * the server, this time with the input buf of the required size. |
| 4810 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4811 | 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] | 4812 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4813 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4814 | struct nfs_getaclargs args = { |
| 4815 | .fh = NFS_FH(inode), |
| 4816 | .acl_pages = pages, |
| 4817 | .acl_len = buflen, |
| 4818 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4819 | struct nfs_getaclres res = { |
| 4820 | .acl_len = buflen, |
| 4821 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4822 | struct rpc_message msg = { |
| 4823 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4824 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4825 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4826 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4827 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4828 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4829 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4830 | /* As long as we're doing a round trip to the server anyway, |
| 4831 | * let's be prepared for a page of acl data. */ |
| 4832 | if (npages == 0) |
| 4833 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4834 | if (npages > ARRAY_SIZE(pages)) |
| 4835 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4836 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4837 | for (i = 0; i < npages; i++) { |
| 4838 | pages[i] = alloc_page(GFP_KERNEL); |
| 4839 | if (!pages[i]) |
| 4840 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4841 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4842 | |
| 4843 | /* for decoding across pages */ |
| 4844 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4845 | if (!res.acl_scratch) |
| 4846 | goto out_free; |
| 4847 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4848 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4849 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4850 | 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] | 4851 | __func__, buf, buflen, npages, args.acl_len); |
| 4852 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4853 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4854 | if (ret) |
| 4855 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4856 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4857 | /* Handle the case where the passed-in buffer is too short */ |
| 4858 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4859 | /* Did the user only issue a request for the acl length? */ |
| 4860 | if (buf == NULL) |
| 4861 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4862 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4863 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4864 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4865 | 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] | 4866 | if (buf) { |
| 4867 | if (res.acl_len > buflen) { |
| 4868 | ret = -ERANGE; |
| 4869 | goto out_free; |
| 4870 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4871 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4872 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4873 | out_ok: |
| 4874 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4875 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4876 | for (i = 0; i < npages; i++) |
| 4877 | if (pages[i]) |
| 4878 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4879 | if (res.acl_scratch) |
| 4880 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4881 | return ret; |
| 4882 | } |
| 4883 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4884 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4885 | { |
| 4886 | struct nfs4_exception exception = { }; |
| 4887 | ssize_t ret; |
| 4888 | do { |
| 4889 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4890 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4891 | if (ret >= 0) |
| 4892 | break; |
| 4893 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4894 | } while (exception.retry); |
| 4895 | return ret; |
| 4896 | } |
| 4897 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4898 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4899 | { |
| 4900 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4901 | int ret; |
| 4902 | |
| 4903 | if (!nfs4_server_supports_acls(server)) |
| 4904 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4905 | ret = nfs_revalidate_inode(server, inode); |
| 4906 | if (ret < 0) |
| 4907 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4908 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4909 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4910 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4911 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4912 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4913 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4914 | return ret; |
| 4915 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4918 | 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] | 4919 | { |
| 4920 | struct nfs_server *server = NFS_SERVER(inode); |
| 4921 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4922 | struct nfs_setaclargs arg = { |
| 4923 | .fh = NFS_FH(inode), |
| 4924 | .acl_pages = pages, |
| 4925 | .acl_len = buflen, |
| 4926 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4927 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4928 | struct rpc_message msg = { |
| 4929 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4930 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4931 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4932 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4933 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4934 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4935 | |
| 4936 | if (!nfs4_server_supports_acls(server)) |
| 4937 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4938 | if (npages > ARRAY_SIZE(pages)) |
| 4939 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4940 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4941 | if (i < 0) |
| 4942 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4943 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4944 | 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] | 4945 | |
| 4946 | /* |
| 4947 | * Free each page after tx, so the only ref left is |
| 4948 | * held by the network stack |
| 4949 | */ |
| 4950 | for (; i > 0; i--) |
| 4951 | put_page(pages[i-1]); |
| 4952 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4953 | /* |
| 4954 | * Acl update can result in inode attribute update. |
| 4955 | * so mark the attribute cache invalid. |
| 4956 | */ |
| 4957 | spin_lock(&inode->i_lock); |
| 4958 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4959 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4960 | nfs_access_zap_cache(inode); |
| 4961 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4962 | return ret; |
| 4963 | } |
| 4964 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4965 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4966 | { |
| 4967 | struct nfs4_exception exception = { }; |
| 4968 | int err; |
| 4969 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4970 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4971 | trace_nfs4_set_acl(inode, err); |
| 4972 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4973 | &exception); |
| 4974 | } while (exception.retry); |
| 4975 | return err; |
| 4976 | } |
| 4977 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4978 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4979 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4980 | size_t buflen) |
| 4981 | { |
| 4982 | struct nfs_server *server = NFS_SERVER(inode); |
| 4983 | struct nfs_fattr fattr; |
| 4984 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4985 | |
| 4986 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4987 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4988 | .fh = NFS_FH(inode), |
| 4989 | .bitmask = bitmask, |
| 4990 | }; |
| 4991 | struct nfs4_getattr_res res = { |
| 4992 | .fattr = &fattr, |
| 4993 | .label = &label, |
| 4994 | .server = server, |
| 4995 | }; |
| 4996 | struct rpc_message msg = { |
| 4997 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4998 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4999 | .rpc_resp = &res, |
| 5000 | }; |
| 5001 | int ret; |
| 5002 | |
| 5003 | nfs_fattr_init(&fattr); |
| 5004 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5005 | 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] | 5006 | if (ret) |
| 5007 | return ret; |
| 5008 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5009 | return -ENOENT; |
| 5010 | if (buflen < label.len) |
| 5011 | return -ERANGE; |
| 5012 | return 0; |
| 5013 | } |
| 5014 | |
| 5015 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5016 | size_t buflen) |
| 5017 | { |
| 5018 | struct nfs4_exception exception = { }; |
| 5019 | int err; |
| 5020 | |
| 5021 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5022 | return -EOPNOTSUPP; |
| 5023 | |
| 5024 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5025 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5026 | trace_nfs4_get_security_label(inode, err); |
| 5027 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5028 | &exception); |
| 5029 | } while (exception.retry); |
| 5030 | return err; |
| 5031 | } |
| 5032 | |
| 5033 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5034 | struct nfs4_label *ilabel, |
| 5035 | struct nfs_fattr *fattr, |
| 5036 | struct nfs4_label *olabel) |
| 5037 | { |
| 5038 | |
| 5039 | struct iattr sattr = {0}; |
| 5040 | struct nfs_server *server = NFS_SERVER(inode); |
| 5041 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5042 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5043 | .fh = NFS_FH(inode), |
| 5044 | .iap = &sattr, |
| 5045 | .server = server, |
| 5046 | .bitmask = bitmask, |
| 5047 | .label = ilabel, |
| 5048 | }; |
| 5049 | struct nfs_setattrres res = { |
| 5050 | .fattr = fattr, |
| 5051 | .label = olabel, |
| 5052 | .server = server, |
| 5053 | }; |
| 5054 | struct rpc_message msg = { |
| 5055 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5056 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5057 | .rpc_resp = &res, |
| 5058 | }; |
| 5059 | int status; |
| 5060 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5061 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5062 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5063 | 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] | 5064 | if (status) |
| 5065 | dprintk("%s failed: %d\n", __func__, status); |
| 5066 | |
| 5067 | return status; |
| 5068 | } |
| 5069 | |
| 5070 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5071 | struct nfs4_label *ilabel, |
| 5072 | struct nfs_fattr *fattr, |
| 5073 | struct nfs4_label *olabel) |
| 5074 | { |
| 5075 | struct nfs4_exception exception = { }; |
| 5076 | int err; |
| 5077 | |
| 5078 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5079 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5080 | fattr, olabel); |
| 5081 | trace_nfs4_set_security_label(inode, err); |
| 5082 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5083 | &exception); |
| 5084 | } while (exception.retry); |
| 5085 | return err; |
| 5086 | } |
| 5087 | |
| 5088 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5089 | 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] | 5090 | { |
| 5091 | struct nfs4_label ilabel, *olabel = NULL; |
| 5092 | struct nfs_fattr fattr; |
| 5093 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5094 | int status; |
| 5095 | |
| 5096 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5097 | return -EOPNOTSUPP; |
| 5098 | |
| 5099 | nfs_fattr_init(&fattr); |
| 5100 | |
| 5101 | ilabel.pi = 0; |
| 5102 | ilabel.lfs = 0; |
| 5103 | ilabel.label = (char *)buf; |
| 5104 | ilabel.len = buflen; |
| 5105 | |
| 5106 | cred = rpc_lookup_cred(); |
| 5107 | if (IS_ERR(cred)) |
| 5108 | return PTR_ERR(cred); |
| 5109 | |
| 5110 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5111 | if (IS_ERR(olabel)) { |
| 5112 | status = -PTR_ERR(olabel); |
| 5113 | goto out; |
| 5114 | } |
| 5115 | |
| 5116 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5117 | if (status == 0) |
| 5118 | nfs_setsecurity(inode, &fattr, olabel); |
| 5119 | |
| 5120 | nfs4_label_free(olabel); |
| 5121 | out: |
| 5122 | put_rpccred(cred); |
| 5123 | return status; |
| 5124 | } |
| 5125 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5126 | |
| 5127 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5128 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5129 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5130 | { |
| 5131 | __be32 verf[2]; |
| 5132 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5133 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5134 | /* An impossible timestamp guarantees this value |
| 5135 | * will never match a generated boot time. */ |
| 5136 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5137 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5138 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5139 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5140 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5141 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5142 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5143 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5144 | } |
| 5145 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5146 | static int |
| 5147 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5148 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5149 | size_t len; |
| 5150 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5151 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5152 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5153 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5154 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5155 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5156 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5157 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5158 | 1 + |
| 5159 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5160 | 1; |
| 5161 | rcu_read_unlock(); |
| 5162 | |
| 5163 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5164 | return -EINVAL; |
| 5165 | |
| 5166 | /* |
| 5167 | * Since this string is allocated at mount time, and held until the |
| 5168 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5169 | * about a memory-reclaim deadlock. |
| 5170 | */ |
| 5171 | str = kmalloc(len, GFP_KERNEL); |
| 5172 | if (!str) |
| 5173 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5174 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5175 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5176 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5177 | clp->cl_ipaddr, |
| 5178 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5179 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5180 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5181 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5182 | clp->cl_owner_id = str; |
| 5183 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5184 | } |
| 5185 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5186 | static int |
| 5187 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5188 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5189 | size_t len; |
| 5190 | char *str; |
| 5191 | |
| 5192 | len = 10 + 10 + 1 + 10 + 1 + |
| 5193 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5194 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5195 | |
| 5196 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5197 | return -EINVAL; |
| 5198 | |
| 5199 | /* |
| 5200 | * Since this string is allocated at mount time, and held until the |
| 5201 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5202 | * about a memory-reclaim deadlock. |
| 5203 | */ |
| 5204 | str = kmalloc(len, GFP_KERNEL); |
| 5205 | if (!str) |
| 5206 | return -ENOMEM; |
| 5207 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5208 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5209 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5210 | nfs4_client_id_uniquifier, |
| 5211 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5212 | clp->cl_owner_id = str; |
| 5213 | return 0; |
| 5214 | } |
| 5215 | |
| 5216 | static int |
| 5217 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5218 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5219 | size_t len; |
| 5220 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5221 | |
| 5222 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5223 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5224 | |
| 5225 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5226 | return nfs4_init_uniquifier_client_string(clp); |
| 5227 | |
| 5228 | len = 10 + 10 + 1 + 10 + 1 + |
| 5229 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5230 | |
| 5231 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5232 | return -EINVAL; |
| 5233 | |
| 5234 | /* |
| 5235 | * Since this string is allocated at mount time, and held until the |
| 5236 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5237 | * about a memory-reclaim deadlock. |
| 5238 | */ |
| 5239 | str = kmalloc(len, GFP_KERNEL); |
| 5240 | if (!str) |
| 5241 | return -ENOMEM; |
| 5242 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5243 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5244 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5245 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5246 | clp->cl_owner_id = str; |
| 5247 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5248 | } |
| 5249 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5250 | /* |
| 5251 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5252 | * services. Advertise one based on the address family of the |
| 5253 | * clientaddr. |
| 5254 | */ |
| 5255 | static unsigned int |
| 5256 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5257 | { |
| 5258 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5259 | return scnprintf(buf, len, "tcp6"); |
| 5260 | else |
| 5261 | return scnprintf(buf, len, "tcp"); |
| 5262 | } |
| 5263 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5264 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5265 | { |
| 5266 | struct nfs4_setclientid *sc = calldata; |
| 5267 | |
| 5268 | if (task->tk_status == 0) |
| 5269 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5270 | } |
| 5271 | |
| 5272 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5273 | .rpc_call_done = nfs4_setclientid_done, |
| 5274 | }; |
| 5275 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5276 | /** |
| 5277 | * nfs4_proc_setclientid - Negotiate client ID |
| 5278 | * @clp: state data structure |
| 5279 | * @program: RPC program for NFSv4 callback service |
| 5280 | * @port: IP port number for NFS4 callback service |
| 5281 | * @cred: RPC credential to use for this call |
| 5282 | * @res: where to place the result |
| 5283 | * |
| 5284 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5285 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5286 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5287 | unsigned short port, struct rpc_cred *cred, |
| 5288 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | { |
| 5290 | nfs4_verifier sc_verifier; |
| 5291 | struct nfs4_setclientid setclientid = { |
| 5292 | .sc_verifier = &sc_verifier, |
| 5293 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5294 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | }; |
| 5296 | struct rpc_message msg = { |
| 5297 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5298 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5299 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5300 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5302 | struct rpc_task *task; |
| 5303 | struct rpc_task_setup task_setup_data = { |
| 5304 | .rpc_client = clp->cl_rpcclient, |
| 5305 | .rpc_message = &msg, |
| 5306 | .callback_ops = &nfs4_setclientid_ops, |
| 5307 | .callback_data = &setclientid, |
| 5308 | .flags = RPC_TASK_TIMEOUT, |
| 5309 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5310 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5312 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5313 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5314 | |
| 5315 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5316 | status = nfs4_init_uniform_client_string(clp); |
| 5317 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5318 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5319 | |
| 5320 | if (status) |
| 5321 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5322 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5323 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5324 | setclientid.sc_netid_len = |
| 5325 | nfs4_init_callback_netid(clp, |
| 5326 | setclientid.sc_netid, |
| 5327 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5328 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5329 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5331 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5332 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5333 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5334 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5335 | task = rpc_run_task(&task_setup_data); |
| 5336 | if (IS_ERR(task)) { |
| 5337 | status = PTR_ERR(task); |
| 5338 | goto out; |
| 5339 | } |
| 5340 | status = task->tk_status; |
| 5341 | if (setclientid.sc_cred) { |
| 5342 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5343 | put_rpccred(setclientid.sc_cred); |
| 5344 | } |
| 5345 | rpc_put_task(task); |
| 5346 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5347 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5348 | dprintk("NFS reply setclientid: %d\n", status); |
| 5349 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5352 | /** |
| 5353 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5354 | * @clp: state data structure |
| 5355 | * @res: result of a previous SETCLIENTID |
| 5356 | * @cred: RPC credential to use for this call |
| 5357 | * |
| 5358 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5359 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5360 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5361 | struct nfs4_setclientid_res *arg, |
| 5362 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | struct rpc_message msg = { |
| 5365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5366 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5367 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5368 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | int status; |
| 5370 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5371 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5372 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5373 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5374 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5375 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5376 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | return status; |
| 5378 | } |
| 5379 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5380 | struct nfs4_delegreturndata { |
| 5381 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5382 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5383 | struct nfs_fh fh; |
| 5384 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5385 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5386 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5387 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5388 | struct inode *inode; |
| 5389 | bool roc; |
| 5390 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5391 | }; |
| 5392 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5393 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5394 | { |
| 5395 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5396 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5397 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5398 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5399 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5400 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5401 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5402 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5403 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5404 | case -NFS4ERR_ADMIN_REVOKED: |
| 5405 | case -NFS4ERR_DELEG_REVOKED: |
| 5406 | case -NFS4ERR_BAD_STATEID: |
| 5407 | case -NFS4ERR_OLD_STATEID: |
| 5408 | case -NFS4ERR_STALE_STATEID: |
| 5409 | case -NFS4ERR_EXPIRED: |
| 5410 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5411 | if (data->roc) |
| 5412 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5413 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5414 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5415 | if (nfs4_async_handle_error(task, data->res.server, |
| 5416 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5417 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5418 | return; |
| 5419 | } |
| 5420 | } |
| 5421 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | static void nfs4_delegreturn_release(void *calldata) |
| 5425 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5426 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5427 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5428 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5429 | if (inode) { |
| 5430 | if (data->roc) |
| 5431 | pnfs_roc_release(inode); |
| 5432 | nfs_iput_and_deactive(inode); |
| 5433 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5434 | kfree(calldata); |
| 5435 | } |
| 5436 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5437 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5438 | { |
| 5439 | struct nfs4_delegreturndata *d_data; |
| 5440 | |
| 5441 | d_data = (struct nfs4_delegreturndata *)data; |
| 5442 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5443 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5444 | return; |
| 5445 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5446 | if (d_data->roc) |
| 5447 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5448 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5449 | nfs4_setup_sequence(d_data->res.server, |
| 5450 | &d_data->args.seq_args, |
| 5451 | &d_data->res.seq_res, |
| 5452 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5453 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5454 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5455 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5456 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5457 | .rpc_call_done = nfs4_delegreturn_done, |
| 5458 | .rpc_release = nfs4_delegreturn_release, |
| 5459 | }; |
| 5460 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5461 | 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] | 5462 | { |
| 5463 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5464 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5465 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5466 | struct rpc_message msg = { |
| 5467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5468 | .rpc_cred = cred, |
| 5469 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5470 | struct rpc_task_setup task_setup_data = { |
| 5471 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5472 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5473 | .callback_ops = &nfs4_delegreturn_ops, |
| 5474 | .flags = RPC_TASK_ASYNC, |
| 5475 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5476 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5477 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5478 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5479 | if (data == NULL) |
| 5480 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5481 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5482 | |
| 5483 | nfs4_state_protect(server->nfs_client, |
| 5484 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5485 | &task_setup_data.rpc_client, &msg); |
| 5486 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5487 | data->args.fhandle = &data->fh; |
| 5488 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5489 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5490 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5491 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5492 | data->res.fattr = &data->fattr; |
| 5493 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5494 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5495 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5496 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5497 | data->inode = nfs_igrab_and_active(inode); |
| 5498 | if (data->inode) |
| 5499 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5500 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5501 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5502 | msg.rpc_argp = &data->args; |
| 5503 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5504 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5505 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5506 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5507 | if (!issync) |
| 5508 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5509 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5510 | if (status != 0) |
| 5511 | goto out; |
| 5512 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5513 | if (status == 0) |
| 5514 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5515 | else |
| 5516 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5517 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5518 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5519 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | } |
| 5521 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5522 | 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] | 5523 | { |
| 5524 | struct nfs_server *server = NFS_SERVER(inode); |
| 5525 | struct nfs4_exception exception = { }; |
| 5526 | int err; |
| 5527 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5528 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5529 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | switch (err) { |
| 5531 | case -NFS4ERR_STALE_STATEID: |
| 5532 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | case 0: |
| 5534 | return 0; |
| 5535 | } |
| 5536 | err = nfs4_handle_exception(server, err, &exception); |
| 5537 | } while (exception.retry); |
| 5538 | return err; |
| 5539 | } |
| 5540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5542 | { |
| 5543 | struct inode *inode = state->inode; |
| 5544 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5545 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5546 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5548 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5550 | struct nfs_lockt_res res = { |
| 5551 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | }; |
| 5553 | struct rpc_message msg = { |
| 5554 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5555 | .rpc_argp = &arg, |
| 5556 | .rpc_resp = &res, |
| 5557 | .rpc_cred = state->owner->so_cred, |
| 5558 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | struct nfs4_lock_state *lsp; |
| 5560 | int status; |
| 5561 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5562 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5563 | status = nfs4_set_lock_state(state, request); |
| 5564 | if (status != 0) |
| 5565 | goto out; |
| 5566 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5567 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5568 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5569 | 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] | 5570 | switch (status) { |
| 5571 | case 0: |
| 5572 | request->fl_type = F_UNLCK; |
| 5573 | break; |
| 5574 | case -NFS4ERR_DENIED: |
| 5575 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5577 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5578 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5579 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | return status; |
| 5581 | } |
| 5582 | |
| 5583 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5584 | { |
| 5585 | struct nfs4_exception exception = { }; |
| 5586 | int err; |
| 5587 | |
| 5588 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5589 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5590 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5591 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | &exception); |
| 5593 | } while (exception.retry); |
| 5594 | return err; |
| 5595 | } |
| 5596 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5597 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5598 | struct nfs_locku_args arg; |
| 5599 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5600 | struct nfs4_lock_state *lsp; |
| 5601 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5602 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5603 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5604 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5605 | }; |
| 5606 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5607 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5608 | struct nfs_open_context *ctx, |
| 5609 | struct nfs4_lock_state *lsp, |
| 5610 | struct nfs_seqid *seqid) |
| 5611 | { |
| 5612 | struct nfs4_unlockdata *p; |
| 5613 | struct inode *inode = lsp->ls_state->inode; |
| 5614 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5615 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5616 | if (p == NULL) |
| 5617 | return NULL; |
| 5618 | p->arg.fh = NFS_FH(inode); |
| 5619 | p->arg.fl = &p->fl; |
| 5620 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5621 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5622 | p->lsp = lsp; |
| 5623 | atomic_inc(&lsp->ls_count); |
| 5624 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5625 | p->ctx = get_nfs_open_context(ctx); |
| 5626 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5627 | p->server = NFS_SERVER(inode); |
| 5628 | return p; |
| 5629 | } |
| 5630 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5631 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5632 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5633 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5634 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5635 | nfs4_put_lock_state(calldata->lsp); |
| 5636 | put_nfs_open_context(calldata->ctx); |
| 5637 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5638 | } |
| 5639 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5640 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5641 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5642 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5643 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5644 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5645 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5646 | switch (task->tk_status) { |
| 5647 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5648 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5649 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5650 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5651 | &calldata->res.stateid)) |
| 5652 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5653 | case -NFS4ERR_BAD_STATEID: |
| 5654 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5655 | case -NFS4ERR_STALE_STATEID: |
| 5656 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5657 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5658 | &calldata->lsp->ls_stateid)) |
| 5659 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5660 | break; |
| 5661 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5662 | if (nfs4_async_handle_error(task, calldata->server, |
| 5663 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5664 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5665 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5666 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5667 | } |
| 5668 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5669 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5670 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5671 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5673 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5674 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5675 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5676 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5677 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5678 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5679 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5680 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5681 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5682 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5683 | &calldata->res.seq_res, |
| 5684 | task) != 0) |
| 5685 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5686 | return; |
| 5687 | out_no_action: |
| 5688 | task->tk_action = NULL; |
| 5689 | out_wait: |
| 5690 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5693 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5694 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5695 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5696 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5697 | }; |
| 5698 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5699 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5700 | struct nfs_open_context *ctx, |
| 5701 | struct nfs4_lock_state *lsp, |
| 5702 | struct nfs_seqid *seqid) |
| 5703 | { |
| 5704 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5705 | struct rpc_message msg = { |
| 5706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5707 | .rpc_cred = ctx->cred, |
| 5708 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5709 | struct rpc_task_setup task_setup_data = { |
| 5710 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5711 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5712 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5713 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5714 | .flags = RPC_TASK_ASYNC, |
| 5715 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5716 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5717 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5718 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5719 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5720 | /* Ensure this is an unlock - when canceling a lock, the |
| 5721 | * canceled lock is passed in, and it won't be an unlock. |
| 5722 | */ |
| 5723 | fl->fl_type = F_UNLCK; |
| 5724 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5725 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5726 | if (data == NULL) { |
| 5727 | nfs_free_seqid(seqid); |
| 5728 | return ERR_PTR(-ENOMEM); |
| 5729 | } |
| 5730 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5731 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5732 | msg.rpc_argp = &data->arg; |
| 5733 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5734 | task_setup_data.callback_data = data; |
| 5735 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5736 | } |
| 5737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5739 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5740 | struct inode *inode = state->inode; |
| 5741 | struct nfs4_state_owner *sp = state->owner; |
| 5742 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5743 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5744 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5745 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5746 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5747 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5748 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5750 | status = nfs4_set_lock_state(state, request); |
| 5751 | /* Unlock _before_ we do the RPC call */ |
| 5752 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5753 | /* Exclude nfs_delegation_claim_locks() */ |
| 5754 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5755 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5756 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5757 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5758 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5759 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5760 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5761 | } |
| 5762 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5763 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5764 | if (status != 0) |
| 5765 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5766 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5767 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5768 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5769 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5770 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5771 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5772 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5773 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5774 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5775 | 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] | 5776 | status = PTR_ERR(task); |
| 5777 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5778 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5779 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5780 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5781 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5782 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5783 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5784 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | } |
| 5786 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5787 | struct nfs4_lockdata { |
| 5788 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5789 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5790 | struct nfs4_lock_state *lsp; |
| 5791 | struct nfs_open_context *ctx; |
| 5792 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5793 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5794 | int rpc_status; |
| 5795 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5796 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5797 | }; |
| 5798 | |
| 5799 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5800 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5801 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5802 | { |
| 5803 | struct nfs4_lockdata *p; |
| 5804 | struct inode *inode = lsp->ls_state->inode; |
| 5805 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5806 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5807 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5808 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5809 | if (p == NULL) |
| 5810 | return NULL; |
| 5811 | |
| 5812 | p->arg.fh = NFS_FH(inode); |
| 5813 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5814 | 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] | 5815 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5816 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5817 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5818 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5819 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5820 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5821 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5822 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5823 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5824 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5825 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5826 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5827 | atomic_inc(&lsp->ls_count); |
| 5828 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5829 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5830 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5831 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5832 | out_free_seqid: |
| 5833 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5834 | out_free: |
| 5835 | kfree(p); |
| 5836 | return NULL; |
| 5837 | } |
| 5838 | |
| 5839 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5840 | { |
| 5841 | struct nfs4_lockdata *data = calldata; |
| 5842 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5844 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5845 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5846 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5847 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5848 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5849 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5850 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5851 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5852 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5853 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5854 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5855 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5856 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5857 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5858 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5859 | &data->lsp->ls_stateid); |
| 5860 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5861 | if (!nfs4_valid_open_stateid(state)) { |
| 5862 | data->rpc_status = -EBADF; |
| 5863 | task->tk_action = NULL; |
| 5864 | goto out_release_open_seqid; |
| 5865 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5866 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5867 | if (nfs4_setup_sequence(data->server, |
| 5868 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5869 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5870 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5871 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5872 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5873 | nfs_release_seqid(data->arg.open_seqid); |
| 5874 | out_release_lock_seqid: |
| 5875 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5876 | out_wait: |
| 5877 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5878 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5879 | } |
| 5880 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5881 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5882 | { |
| 5883 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5884 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5885 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5886 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5887 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5888 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5889 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5890 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5891 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5892 | switch (task->tk_status) { |
| 5893 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5894 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5895 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5896 | if (data->arg.new_lock) { |
| 5897 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5898 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5899 | rpc_restart_call_prepare(task); |
| 5900 | break; |
| 5901 | } |
| 5902 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5903 | if (data->arg.new_lock_owner != 0) { |
| 5904 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5905 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5906 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5907 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5908 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5909 | break; |
| 5910 | case -NFS4ERR_BAD_STATEID: |
| 5911 | case -NFS4ERR_OLD_STATEID: |
| 5912 | case -NFS4ERR_STALE_STATEID: |
| 5913 | case -NFS4ERR_EXPIRED: |
| 5914 | if (data->arg.new_lock_owner != 0) { |
| 5915 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5916 | &lsp->ls_state->open_stateid)) |
| 5917 | rpc_restart_call_prepare(task); |
| 5918 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5919 | &lsp->ls_stateid)) |
| 5920 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5921 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5922 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | static void nfs4_lock_release(void *calldata) |
| 5926 | { |
| 5927 | struct nfs4_lockdata *data = calldata; |
| 5928 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5929 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5930 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5931 | if (data->cancelled != 0) { |
| 5932 | struct rpc_task *task; |
| 5933 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5934 | data->arg.lock_seqid); |
| 5935 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5936 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5937 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5938 | } else |
| 5939 | nfs_free_seqid(data->arg.lock_seqid); |
| 5940 | nfs4_put_lock_state(data->lsp); |
| 5941 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5942 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5943 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5944 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5948 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5949 | .rpc_call_done = nfs4_lock_done, |
| 5950 | .rpc_release = nfs4_lock_release, |
| 5951 | }; |
| 5952 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5953 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5954 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5955 | switch (error) { |
| 5956 | case -NFS4ERR_ADMIN_REVOKED: |
| 5957 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5958 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5959 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5960 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5961 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5962 | break; |
| 5963 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5964 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5965 | case -NFS4ERR_EXPIRED: |
| 5966 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5967 | }; |
| 5968 | } |
| 5969 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5970 | 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] | 5971 | { |
| 5972 | struct nfs4_lockdata *data; |
| 5973 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5974 | struct rpc_message msg = { |
| 5975 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5976 | .rpc_cred = state->owner->so_cred, |
| 5977 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5978 | struct rpc_task_setup task_setup_data = { |
| 5979 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5980 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5981 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5982 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5983 | .flags = RPC_TASK_ASYNC, |
| 5984 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5985 | int ret; |
| 5986 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5987 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5988 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5989 | fl->fl_u.nfs4_fl.owner, |
| 5990 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5991 | if (data == NULL) |
| 5992 | return -ENOMEM; |
| 5993 | if (IS_SETLKW(cmd)) |
| 5994 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5995 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5996 | msg.rpc_argp = &data->arg; |
| 5997 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5998 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5999 | if (recovery_type > NFS_LOCK_NEW) { |
| 6000 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6001 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6002 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6003 | } else |
| 6004 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6005 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6006 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6007 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6008 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6009 | if (ret == 0) { |
| 6010 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6011 | if (ret) |
| 6012 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6013 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6014 | } else |
| 6015 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6016 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6017 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6018 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6019 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6023 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6024 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6025 | struct nfs4_exception exception = { |
| 6026 | .inode = state->inode, |
| 6027 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6028 | int err; |
| 6029 | |
| 6030 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6031 | /* Cache the lock if possible... */ |
| 6032 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6033 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6034 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6035 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | nfs4_handle_exception(server, err, &exception); |
| 6038 | } while (exception.retry); |
| 6039 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6043 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6044 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6045 | struct nfs4_exception exception = { |
| 6046 | .inode = state->inode, |
| 6047 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6048 | int err; |
| 6049 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6050 | err = nfs4_set_lock_state(state, request); |
| 6051 | if (err != 0) |
| 6052 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6053 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6054 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6055 | return 0; |
| 6056 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6057 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6058 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6059 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6060 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6061 | switch (err) { |
| 6062 | default: |
| 6063 | goto out; |
| 6064 | case -NFS4ERR_GRACE: |
| 6065 | case -NFS4ERR_DELAY: |
| 6066 | nfs4_handle_exception(server, err, &exception); |
| 6067 | err = 0; |
| 6068 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6069 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6070 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6071 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | } |
| 6073 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6074 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6075 | /** |
| 6076 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6077 | * |
| 6078 | * @state: NFSv4 state for an inode |
| 6079 | * |
| 6080 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6081 | * Otherwise a negative NFS4ERR value is returned. |
| 6082 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6083 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6084 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6085 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6086 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6087 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6088 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6089 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6090 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6091 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6092 | |
| 6093 | status = nfs41_test_stateid(server, |
| 6094 | &lsp->ls_stateid, |
| 6095 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6096 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6097 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6098 | /* Free the stateid unless the server |
| 6099 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 6100 | if (status != -NFS4ERR_BAD_STATEID) |
| 6101 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6102 | &lsp->ls_stateid, |
| 6103 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6104 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6105 | ret = status; |
| 6106 | } |
| 6107 | } |
| 6108 | }; |
| 6109 | |
| 6110 | return ret; |
| 6111 | } |
| 6112 | |
| 6113 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6114 | { |
| 6115 | int status = NFS_OK; |
| 6116 | |
| 6117 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6118 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6119 | if (status != NFS_OK) |
| 6120 | status = nfs4_lock_expired(state, request); |
| 6121 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6122 | } |
| 6123 | #endif |
| 6124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6126 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6127 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6128 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6129 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6130 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6131 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6132 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6133 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6134 | if (status < 0) |
| 6135 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6136 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6137 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6138 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6139 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6140 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6141 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6142 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6143 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6144 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6145 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6146 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6147 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6148 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6149 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6150 | out: |
| 6151 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | return status; |
| 6153 | } |
| 6154 | |
| 6155 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6156 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6157 | struct nfs4_exception exception = { |
| 6158 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6159 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6160 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6161 | int err; |
| 6162 | |
| 6163 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6164 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6165 | if (err == -NFS4ERR_DENIED) |
| 6166 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6167 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6168 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6169 | } while (exception.retry); |
| 6170 | return err; |
| 6171 | } |
| 6172 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6173 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6174 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6175 | |
| 6176 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6177 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6178 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6179 | { |
| 6180 | int status = -ERESTARTSYS; |
| 6181 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6182 | |
| 6183 | while(!signalled()) { |
| 6184 | status = nfs4_proc_setlk(state, cmd, request); |
| 6185 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6186 | break; |
| 6187 | freezable_schedule_timeout_interruptible(timeout); |
| 6188 | timeout *= 2; |
| 6189 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6190 | status = -ERESTARTSYS; |
| 6191 | } |
| 6192 | return status; |
| 6193 | } |
| 6194 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6195 | #ifdef CONFIG_NFS_V4_1 |
| 6196 | struct nfs4_lock_waiter { |
| 6197 | struct task_struct *task; |
| 6198 | struct inode *inode; |
| 6199 | struct nfs_lowner *owner; |
| 6200 | bool notified; |
| 6201 | }; |
| 6202 | |
| 6203 | static int |
| 6204 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6205 | { |
| 6206 | int ret; |
| 6207 | struct cb_notify_lock_args *cbnl = key; |
| 6208 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6209 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6210 | *wowner = waiter->owner; |
| 6211 | |
| 6212 | /* Only wake if the callback was for the same owner */ |
| 6213 | if (lowner->clientid != wowner->clientid || |
| 6214 | lowner->id != wowner->id || |
| 6215 | lowner->s_dev != wowner->s_dev) |
| 6216 | return 0; |
| 6217 | |
| 6218 | /* Make sure it's for the right inode */ |
| 6219 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6220 | return 0; |
| 6221 | |
| 6222 | waiter->notified = true; |
| 6223 | |
| 6224 | /* override "private" so we can use default_wake_function */ |
| 6225 | wait->private = waiter->task; |
| 6226 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6227 | wait->private = waiter; |
| 6228 | return ret; |
| 6229 | } |
| 6230 | |
| 6231 | static int |
| 6232 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6233 | { |
| 6234 | int status = -ERESTARTSYS; |
| 6235 | unsigned long flags; |
| 6236 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6237 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6238 | struct nfs_client *clp = server->nfs_client; |
| 6239 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6240 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6241 | .id = lsp->ls_seqid.owner_id, |
| 6242 | .s_dev = server->s_dev }; |
| 6243 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6244 | .inode = state->inode, |
| 6245 | .owner = &owner, |
| 6246 | .notified = false }; |
| 6247 | wait_queue_t wait; |
| 6248 | |
| 6249 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6250 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6251 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6252 | |
| 6253 | init_wait(&wait); |
| 6254 | wait.private = &waiter; |
| 6255 | wait.func = nfs4_wake_lock_waiter; |
| 6256 | add_wait_queue(q, &wait); |
| 6257 | |
| 6258 | while(!signalled()) { |
| 6259 | status = nfs4_proc_setlk(state, cmd, request); |
| 6260 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6261 | break; |
| 6262 | |
| 6263 | status = -ERESTARTSYS; |
| 6264 | spin_lock_irqsave(&q->lock, flags); |
| 6265 | if (waiter.notified) { |
| 6266 | spin_unlock_irqrestore(&q->lock, flags); |
| 6267 | continue; |
| 6268 | } |
| 6269 | set_current_state(TASK_INTERRUPTIBLE); |
| 6270 | spin_unlock_irqrestore(&q->lock, flags); |
| 6271 | |
| 6272 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6273 | } |
| 6274 | |
| 6275 | finish_wait(q, &wait); |
| 6276 | return status; |
| 6277 | } |
| 6278 | #else /* !CONFIG_NFS_V4_1 */ |
| 6279 | static inline int |
| 6280 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6281 | { |
| 6282 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6283 | } |
| 6284 | #endif |
| 6285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | static int |
| 6287 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6288 | { |
| 6289 | struct nfs_open_context *ctx; |
| 6290 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | int status; |
| 6292 | |
| 6293 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6294 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | state = ctx->state; |
| 6296 | |
| 6297 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6298 | return -EINVAL; |
| 6299 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6300 | if (IS_GETLK(cmd)) { |
| 6301 | if (state != NULL) |
| 6302 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6303 | return 0; |
| 6304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6305 | |
| 6306 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6307 | return -EINVAL; |
| 6308 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6309 | if (request->fl_type == F_UNLCK) { |
| 6310 | if (state != NULL) |
| 6311 | return nfs4_proc_unlck(state, cmd, request); |
| 6312 | return 0; |
| 6313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6315 | if (state == NULL) |
| 6316 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6317 | |
| 6318 | if ((request->fl_flags & FL_POSIX) && |
| 6319 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6320 | return -ENOLCK; |
| 6321 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6322 | /* |
| 6323 | * Don't rely on the VFS having checked the file open mode, |
| 6324 | * since it won't do this for flock() locks. |
| 6325 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6326 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6327 | case F_RDLCK: |
| 6328 | if (!(filp->f_mode & FMODE_READ)) |
| 6329 | return -EBADF; |
| 6330 | break; |
| 6331 | case F_WRLCK: |
| 6332 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6333 | return -EBADF; |
| 6334 | } |
| 6335 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6336 | status = nfs4_set_lock_state(state, request); |
| 6337 | if (status != 0) |
| 6338 | return status; |
| 6339 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6340 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | } |
| 6342 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6343 | 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] | 6344 | { |
| 6345 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6346 | int err; |
| 6347 | |
| 6348 | err = nfs4_set_lock_state(state, fl); |
| 6349 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6350 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6351 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6352 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6353 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6354 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6355 | struct nfs_release_lockowner_data { |
| 6356 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6357 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6358 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6359 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6360 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6361 | }; |
| 6362 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6363 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6364 | { |
| 6365 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6366 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6367 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6368 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6369 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6370 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6374 | { |
| 6375 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6376 | struct nfs_server *server = data->server; |
| 6377 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6378 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6379 | |
| 6380 | switch (task->tk_status) { |
| 6381 | case 0: |
| 6382 | renew_lease(server, data->timestamp); |
| 6383 | break; |
| 6384 | case -NFS4ERR_STALE_CLIENTID: |
| 6385 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6386 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6387 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6388 | case -NFS4ERR_LEASE_MOVED: |
| 6389 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6390 | if (nfs4_async_handle_error(task, server, |
| 6391 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6392 | rpc_restart_call_prepare(task); |
| 6393 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6394 | } |
| 6395 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6396 | static void nfs4_release_lockowner_release(void *calldata) |
| 6397 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6398 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6399 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6400 | kfree(calldata); |
| 6401 | } |
| 6402 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6403 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6404 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6405 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6406 | .rpc_release = nfs4_release_lockowner_release, |
| 6407 | }; |
| 6408 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6409 | static void |
| 6410 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6411 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6412 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6413 | struct rpc_message msg = { |
| 6414 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6415 | }; |
| 6416 | |
| 6417 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6418 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6419 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6420 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6421 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6422 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6423 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6424 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6425 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6426 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6427 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6428 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6429 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6430 | msg.rpc_resp = &data->res; |
| 6431 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6432 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6433 | } |
| 6434 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6435 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6436 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6437 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6438 | struct dentry *unused, struct inode *inode, |
| 6439 | const char *key, const void *buf, |
| 6440 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6441 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6442 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6443 | } |
| 6444 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6445 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6446 | struct dentry *unused, struct inode *inode, |
| 6447 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6448 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6449 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6450 | } |
| 6451 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6452 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6453 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6454 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6455 | } |
| 6456 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6457 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6458 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6459 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6460 | struct dentry *unused, struct inode *inode, |
| 6461 | const char *key, const void *buf, |
| 6462 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6463 | { |
| 6464 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6465 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6466 | |
| 6467 | return -EOPNOTSUPP; |
| 6468 | } |
| 6469 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6470 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6471 | struct dentry *unused, struct inode *inode, |
| 6472 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6473 | { |
| 6474 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6475 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6476 | return -EOPNOTSUPP; |
| 6477 | } |
| 6478 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6479 | static ssize_t |
| 6480 | 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] | 6481 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6482 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6483 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6484 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6485 | len = security_inode_listsecurity(inode, list, list_len); |
| 6486 | if (list_len && len > list_len) |
| 6487 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6488 | } |
| 6489 | return len; |
| 6490 | } |
| 6491 | |
| 6492 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6493 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6494 | .get = nfs4_xattr_get_nfs4_label, |
| 6495 | .set = nfs4_xattr_set_nfs4_label, |
| 6496 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6497 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6498 | #else |
| 6499 | |
| 6500 | static ssize_t |
| 6501 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6502 | { |
| 6503 | return 0; |
| 6504 | } |
| 6505 | |
| 6506 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6507 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6508 | /* |
| 6509 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6510 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6511 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6512 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6513 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6514 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6515 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6516 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6517 | return; |
| 6518 | |
| 6519 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6520 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6521 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6522 | fattr->nlink = 2; |
| 6523 | } |
| 6524 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6525 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6526 | const struct qstr *name, |
| 6527 | struct nfs4_fs_locations *fs_locations, |
| 6528 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6529 | { |
| 6530 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6531 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6532 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6533 | }; |
| 6534 | struct nfs4_fs_locations_arg args = { |
| 6535 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6536 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6537 | .page = page, |
| 6538 | .bitmask = bitmask, |
| 6539 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6540 | struct nfs4_fs_locations_res res = { |
| 6541 | .fs_locations = fs_locations, |
| 6542 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6543 | struct rpc_message msg = { |
| 6544 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6545 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6546 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6547 | }; |
| 6548 | int status; |
| 6549 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6550 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6551 | |
| 6552 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6553 | * is not supported */ |
| 6554 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6555 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6556 | else |
| 6557 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6558 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6559 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6560 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6561 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6562 | 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] | 6563 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6564 | return status; |
| 6565 | } |
| 6566 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6567 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6568 | const struct qstr *name, |
| 6569 | struct nfs4_fs_locations *fs_locations, |
| 6570 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6571 | { |
| 6572 | struct nfs4_exception exception = { }; |
| 6573 | int err; |
| 6574 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6575 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6576 | fs_locations, page); |
| 6577 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6578 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6579 | &exception); |
| 6580 | } while (exception.retry); |
| 6581 | return err; |
| 6582 | } |
| 6583 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6584 | /* |
| 6585 | * This operation also signals the server that this client is |
| 6586 | * performing migration recovery. The server can stop returning |
| 6587 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6588 | * appended to this compound to identify the client ID which is |
| 6589 | * performing recovery. |
| 6590 | */ |
| 6591 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6592 | struct nfs4_fs_locations *locations, |
| 6593 | struct page *page, struct rpc_cred *cred) |
| 6594 | { |
| 6595 | struct nfs_server *server = NFS_SERVER(inode); |
| 6596 | struct rpc_clnt *clnt = server->client; |
| 6597 | u32 bitmask[2] = { |
| 6598 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6599 | }; |
| 6600 | struct nfs4_fs_locations_arg args = { |
| 6601 | .clientid = server->nfs_client->cl_clientid, |
| 6602 | .fh = NFS_FH(inode), |
| 6603 | .page = page, |
| 6604 | .bitmask = bitmask, |
| 6605 | .migration = 1, /* skip LOOKUP */ |
| 6606 | .renew = 1, /* append RENEW */ |
| 6607 | }; |
| 6608 | struct nfs4_fs_locations_res res = { |
| 6609 | .fs_locations = locations, |
| 6610 | .migration = 1, |
| 6611 | .renew = 1, |
| 6612 | }; |
| 6613 | struct rpc_message msg = { |
| 6614 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6615 | .rpc_argp = &args, |
| 6616 | .rpc_resp = &res, |
| 6617 | .rpc_cred = cred, |
| 6618 | }; |
| 6619 | unsigned long now = jiffies; |
| 6620 | int status; |
| 6621 | |
| 6622 | nfs_fattr_init(&locations->fattr); |
| 6623 | locations->server = server; |
| 6624 | locations->nlocations = 0; |
| 6625 | |
| 6626 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6627 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6628 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6629 | &args.seq_args, &res.seq_res); |
| 6630 | if (status) |
| 6631 | return status; |
| 6632 | |
| 6633 | renew_lease(server, now); |
| 6634 | return 0; |
| 6635 | } |
| 6636 | |
| 6637 | #ifdef CONFIG_NFS_V4_1 |
| 6638 | |
| 6639 | /* |
| 6640 | * This operation also signals the server that this client is |
| 6641 | * performing migration recovery. The server can stop asserting |
| 6642 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6643 | * performing this operation is identified in the SEQUENCE |
| 6644 | * operation in this compound. |
| 6645 | * |
| 6646 | * When the client supports GETATTR(fs_locations_info), it can |
| 6647 | * be plumbed in here. |
| 6648 | */ |
| 6649 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6650 | struct nfs4_fs_locations *locations, |
| 6651 | struct page *page, struct rpc_cred *cred) |
| 6652 | { |
| 6653 | struct nfs_server *server = NFS_SERVER(inode); |
| 6654 | struct rpc_clnt *clnt = server->client; |
| 6655 | u32 bitmask[2] = { |
| 6656 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6657 | }; |
| 6658 | struct nfs4_fs_locations_arg args = { |
| 6659 | .fh = NFS_FH(inode), |
| 6660 | .page = page, |
| 6661 | .bitmask = bitmask, |
| 6662 | .migration = 1, /* skip LOOKUP */ |
| 6663 | }; |
| 6664 | struct nfs4_fs_locations_res res = { |
| 6665 | .fs_locations = locations, |
| 6666 | .migration = 1, |
| 6667 | }; |
| 6668 | struct rpc_message msg = { |
| 6669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6670 | .rpc_argp = &args, |
| 6671 | .rpc_resp = &res, |
| 6672 | .rpc_cred = cred, |
| 6673 | }; |
| 6674 | int status; |
| 6675 | |
| 6676 | nfs_fattr_init(&locations->fattr); |
| 6677 | locations->server = server; |
| 6678 | locations->nlocations = 0; |
| 6679 | |
| 6680 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6681 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6682 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6683 | &args.seq_args, &res.seq_res); |
| 6684 | if (status == NFS4_OK && |
| 6685 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6686 | status = -NFS4ERR_LEASE_MOVED; |
| 6687 | return status; |
| 6688 | } |
| 6689 | |
| 6690 | #endif /* CONFIG_NFS_V4_1 */ |
| 6691 | |
| 6692 | /** |
| 6693 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6694 | * @inode: inode on FSID that is migrating |
| 6695 | * @locations: result of query |
| 6696 | * @page: buffer |
| 6697 | * @cred: credential to use for this operation |
| 6698 | * |
| 6699 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6700 | * operation failed, or a negative errno if a local error occurred. |
| 6701 | * |
| 6702 | * On success, "locations" is filled in, but if the server has |
| 6703 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6704 | * asserted. |
| 6705 | * |
| 6706 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6707 | * from this client that require migration recovery. |
| 6708 | */ |
| 6709 | int nfs4_proc_get_locations(struct inode *inode, |
| 6710 | struct nfs4_fs_locations *locations, |
| 6711 | struct page *page, struct rpc_cred *cred) |
| 6712 | { |
| 6713 | struct nfs_server *server = NFS_SERVER(inode); |
| 6714 | struct nfs_client *clp = server->nfs_client; |
| 6715 | const struct nfs4_mig_recovery_ops *ops = |
| 6716 | clp->cl_mvops->mig_recovery_ops; |
| 6717 | struct nfs4_exception exception = { }; |
| 6718 | int status; |
| 6719 | |
| 6720 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6721 | (unsigned long long)server->fsid.major, |
| 6722 | (unsigned long long)server->fsid.minor, |
| 6723 | clp->cl_hostname); |
| 6724 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6725 | |
| 6726 | do { |
| 6727 | status = ops->get_locations(inode, locations, page, cred); |
| 6728 | if (status != -NFS4ERR_DELAY) |
| 6729 | break; |
| 6730 | nfs4_handle_exception(server, status, &exception); |
| 6731 | } while (exception.retry); |
| 6732 | return status; |
| 6733 | } |
| 6734 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6735 | /* |
| 6736 | * This operation also signals the server that this client is |
| 6737 | * performing "lease moved" recovery. The server can stop |
| 6738 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6739 | * is appended to this compound to identify the client ID which is |
| 6740 | * performing recovery. |
| 6741 | */ |
| 6742 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6743 | { |
| 6744 | struct nfs_server *server = NFS_SERVER(inode); |
| 6745 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6746 | struct rpc_clnt *clnt = server->client; |
| 6747 | struct nfs4_fsid_present_arg args = { |
| 6748 | .fh = NFS_FH(inode), |
| 6749 | .clientid = clp->cl_clientid, |
| 6750 | .renew = 1, /* append RENEW */ |
| 6751 | }; |
| 6752 | struct nfs4_fsid_present_res res = { |
| 6753 | .renew = 1, |
| 6754 | }; |
| 6755 | struct rpc_message msg = { |
| 6756 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6757 | .rpc_argp = &args, |
| 6758 | .rpc_resp = &res, |
| 6759 | .rpc_cred = cred, |
| 6760 | }; |
| 6761 | unsigned long now = jiffies; |
| 6762 | int status; |
| 6763 | |
| 6764 | res.fh = nfs_alloc_fhandle(); |
| 6765 | if (res.fh == NULL) |
| 6766 | return -ENOMEM; |
| 6767 | |
| 6768 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6769 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6770 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6771 | &args.seq_args, &res.seq_res); |
| 6772 | nfs_free_fhandle(res.fh); |
| 6773 | if (status) |
| 6774 | return status; |
| 6775 | |
| 6776 | do_renew_lease(clp, now); |
| 6777 | return 0; |
| 6778 | } |
| 6779 | |
| 6780 | #ifdef CONFIG_NFS_V4_1 |
| 6781 | |
| 6782 | /* |
| 6783 | * This operation also signals the server that this client is |
| 6784 | * performing "lease moved" recovery. The server can stop asserting |
| 6785 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6786 | * this operation is identified in the SEQUENCE operation in this |
| 6787 | * compound. |
| 6788 | */ |
| 6789 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6790 | { |
| 6791 | struct nfs_server *server = NFS_SERVER(inode); |
| 6792 | struct rpc_clnt *clnt = server->client; |
| 6793 | struct nfs4_fsid_present_arg args = { |
| 6794 | .fh = NFS_FH(inode), |
| 6795 | }; |
| 6796 | struct nfs4_fsid_present_res res = { |
| 6797 | }; |
| 6798 | struct rpc_message msg = { |
| 6799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6800 | .rpc_argp = &args, |
| 6801 | .rpc_resp = &res, |
| 6802 | .rpc_cred = cred, |
| 6803 | }; |
| 6804 | int status; |
| 6805 | |
| 6806 | res.fh = nfs_alloc_fhandle(); |
| 6807 | if (res.fh == NULL) |
| 6808 | return -ENOMEM; |
| 6809 | |
| 6810 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6811 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6812 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6813 | &args.seq_args, &res.seq_res); |
| 6814 | nfs_free_fhandle(res.fh); |
| 6815 | if (status == NFS4_OK && |
| 6816 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6817 | status = -NFS4ERR_LEASE_MOVED; |
| 6818 | return status; |
| 6819 | } |
| 6820 | |
| 6821 | #endif /* CONFIG_NFS_V4_1 */ |
| 6822 | |
| 6823 | /** |
| 6824 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6825 | * @inode: inode on FSID to check |
| 6826 | * @cred: credential to use for this operation |
| 6827 | * |
| 6828 | * Server indicates whether the FSID is present, moved, or not |
| 6829 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6830 | * condition for this client ID. |
| 6831 | * |
| 6832 | * Returns NFS4_OK if the FSID is present on this server, |
| 6833 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6834 | * NFS4ERR code if some error occurred on the server, or a |
| 6835 | * negative errno if a local failure occurred. |
| 6836 | */ |
| 6837 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6838 | { |
| 6839 | struct nfs_server *server = NFS_SERVER(inode); |
| 6840 | struct nfs_client *clp = server->nfs_client; |
| 6841 | const struct nfs4_mig_recovery_ops *ops = |
| 6842 | clp->cl_mvops->mig_recovery_ops; |
| 6843 | struct nfs4_exception exception = { }; |
| 6844 | int status; |
| 6845 | |
| 6846 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6847 | (unsigned long long)server->fsid.major, |
| 6848 | (unsigned long long)server->fsid.minor, |
| 6849 | clp->cl_hostname); |
| 6850 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6851 | |
| 6852 | do { |
| 6853 | status = ops->fsid_present(inode, cred); |
| 6854 | if (status != -NFS4ERR_DELAY) |
| 6855 | break; |
| 6856 | nfs4_handle_exception(server, status, &exception); |
| 6857 | } while (exception.retry); |
| 6858 | return status; |
| 6859 | } |
| 6860 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6861 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6862 | * If 'use_integrity' is true and the state managment nfs_client |
| 6863 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6864 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6865 | * Considerations sections. Otherwise, just use the user cred with the |
| 6866 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6867 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6868 | 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] | 6869 | { |
| 6870 | int status; |
| 6871 | struct nfs4_secinfo_arg args = { |
| 6872 | .dir_fh = NFS_FH(dir), |
| 6873 | .name = name, |
| 6874 | }; |
| 6875 | struct nfs4_secinfo_res res = { |
| 6876 | .flavors = flavors, |
| 6877 | }; |
| 6878 | struct rpc_message msg = { |
| 6879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6880 | .rpc_argp = &args, |
| 6881 | .rpc_resp = &res, |
| 6882 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6883 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6884 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6885 | |
| 6886 | if (use_integrity) { |
| 6887 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6888 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6889 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6890 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6891 | |
| 6892 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6893 | |
| 6894 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6895 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6896 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6897 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6898 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6899 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6900 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6901 | if (cred) |
| 6902 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6903 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6904 | return status; |
| 6905 | } |
| 6906 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6907 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6908 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6909 | { |
| 6910 | struct nfs4_exception exception = { }; |
| 6911 | int err; |
| 6912 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6913 | err = -NFS4ERR_WRONGSEC; |
| 6914 | |
| 6915 | /* try to use integrity protection with machine cred */ |
| 6916 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6917 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6918 | |
| 6919 | /* |
| 6920 | * if unable to use integrity protection, or SECINFO with |
| 6921 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6922 | * disallowed by spec, but exists in deployed servers) use |
| 6923 | * the current filesystem's rpc_client and the user cred. |
| 6924 | */ |
| 6925 | if (err == -NFS4ERR_WRONGSEC) |
| 6926 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6927 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6928 | trace_nfs4_secinfo(dir, name, err); |
| 6929 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6930 | &exception); |
| 6931 | } while (exception.retry); |
| 6932 | return err; |
| 6933 | } |
| 6934 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6935 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6936 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6937 | * Check the exchange flags returned by the server for invalid flags, having |
| 6938 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6939 | * DS flags set. |
| 6940 | */ |
| 6941 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6942 | { |
| 6943 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6944 | goto out_inval; |
| 6945 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6946 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6947 | goto out_inval; |
| 6948 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6949 | goto out_inval; |
| 6950 | return NFS_OK; |
| 6951 | out_inval: |
| 6952 | return -NFS4ERR_INVAL; |
| 6953 | } |
| 6954 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6955 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6956 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6957 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6958 | { |
| 6959 | if (a->server_scope_sz == b->server_scope_sz && |
| 6960 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6961 | return true; |
| 6962 | |
| 6963 | return false; |
| 6964 | } |
| 6965 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6966 | static void |
| 6967 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6968 | { |
| 6969 | } |
| 6970 | |
| 6971 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6972 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6973 | }; |
| 6974 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6975 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6976 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6977 | * |
| 6978 | * The 4.1 client currently uses the same TCP connection for the |
| 6979 | * fore and backchannel. |
| 6980 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6981 | static |
| 6982 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6983 | struct rpc_xprt *xprt, |
| 6984 | struct nfs_client *clp, |
| 6985 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6986 | { |
| 6987 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6988 | struct nfs41_bind_conn_to_session_args args = { |
| 6989 | .client = clp, |
| 6990 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6991 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6992 | struct nfs41_bind_conn_to_session_res res; |
| 6993 | struct rpc_message msg = { |
| 6994 | .rpc_proc = |
| 6995 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6996 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6997 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6998 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6999 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7000 | struct rpc_task_setup task_setup_data = { |
| 7001 | .rpc_client = clnt, |
| 7002 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7003 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7004 | .rpc_message = &msg, |
| 7005 | .flags = RPC_TASK_TIMEOUT, |
| 7006 | }; |
| 7007 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7008 | |
| 7009 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7010 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7011 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7012 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7013 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7014 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7015 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7016 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7017 | args.dir = NFS4_CDFC4_FORE; |
| 7018 | |
| 7019 | task = rpc_run_task(&task_setup_data); |
| 7020 | if (!IS_ERR(task)) { |
| 7021 | status = task->tk_status; |
| 7022 | rpc_put_task(task); |
| 7023 | } else |
| 7024 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7025 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7026 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7027 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7028 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7029 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7030 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7031 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7032 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7033 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7034 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7035 | __func__); |
| 7036 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7037 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7038 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7039 | 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] | 7040 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7041 | __func__); |
| 7042 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7043 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7044 | } |
| 7045 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7046 | out: |
| 7047 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7048 | return status; |
| 7049 | } |
| 7050 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7051 | struct rpc_bind_conn_calldata { |
| 7052 | struct nfs_client *clp; |
| 7053 | struct rpc_cred *cred; |
| 7054 | }; |
| 7055 | |
| 7056 | static int |
| 7057 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7058 | struct rpc_xprt *xprt, |
| 7059 | void *calldata) |
| 7060 | { |
| 7061 | struct rpc_bind_conn_calldata *p = calldata; |
| 7062 | |
| 7063 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7064 | } |
| 7065 | |
| 7066 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7067 | { |
| 7068 | struct rpc_bind_conn_calldata data = { |
| 7069 | .clp = clp, |
| 7070 | .cred = cred, |
| 7071 | }; |
| 7072 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7073 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7074 | } |
| 7075 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7076 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7077 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7078 | * 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] | 7079 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7080 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7081 | .how = SP4_MACH_CRED, |
| 7082 | .enforce.u.words = { |
| 7083 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7084 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7085 | 1 << (OP_CREATE_SESSION - 32) | |
| 7086 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7087 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7088 | }, |
| 7089 | .allow.u.words = { |
| 7090 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7091 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7092 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7093 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7094 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7095 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7096 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7097 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7098 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7099 | 1 << (OP_FREE_STATEID - 32) | |
| 7100 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7101 | } |
| 7102 | }; |
| 7103 | |
| 7104 | /* |
| 7105 | * Select the state protection mode for client `clp' given the server results |
| 7106 | * from exchange_id in `sp'. |
| 7107 | * |
| 7108 | * Returns 0 on success, negative errno otherwise. |
| 7109 | */ |
| 7110 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7111 | struct nfs41_state_protection *sp) |
| 7112 | { |
| 7113 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7114 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7115 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7116 | 1 << (OP_CREATE_SESSION - 32) | |
| 7117 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7118 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7119 | }; |
| 7120 | unsigned int i; |
| 7121 | |
| 7122 | if (sp->how == SP4_MACH_CRED) { |
| 7123 | /* Print state protect result */ |
| 7124 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7125 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7126 | if (test_bit(i, sp->enforce.u.longs)) |
| 7127 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7128 | if (test_bit(i, sp->allow.u.longs)) |
| 7129 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7130 | } |
| 7131 | |
| 7132 | /* make sure nothing is on enforce list that isn't supported */ |
| 7133 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7134 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7135 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7136 | return -EINVAL; |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | /* |
| 7141 | * Minimal mode - state operations are allowed to use machine |
| 7142 | * credential. Note this already happens by default, so the |
| 7143 | * client doesn't have to do anything more than the negotiation. |
| 7144 | * |
| 7145 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7146 | * we're already using the machine cred for exchange_id |
| 7147 | * and will never use a different cred. |
| 7148 | */ |
| 7149 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7150 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7151 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7152 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7153 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7154 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7155 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7156 | } else { |
| 7157 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7158 | return -EINVAL; |
| 7159 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7160 | |
| 7161 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7162 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7163 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7164 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7165 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7166 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7167 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7168 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7169 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7170 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7171 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7172 | &clp->cl_sp4_flags); |
| 7173 | } |
| 7174 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7175 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7176 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7177 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7178 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7179 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7180 | |
| 7181 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7182 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7183 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7184 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7185 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7186 | |
| 7187 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7188 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7189 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7190 | } |
| 7191 | |
| 7192 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7193 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7194 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7195 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | return 0; |
| 7199 | } |
| 7200 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7201 | struct nfs41_exchange_id_data { |
| 7202 | struct nfs41_exchange_id_res res; |
| 7203 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7204 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7205 | int rpc_status; |
| 7206 | }; |
| 7207 | |
| 7208 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7209 | { |
| 7210 | struct nfs41_exchange_id_data *cdata = |
| 7211 | (struct nfs41_exchange_id_data *)data; |
| 7212 | struct nfs_client *clp = cdata->args.client; |
| 7213 | int status = task->tk_status; |
| 7214 | |
| 7215 | trace_nfs4_exchange_id(clp, status); |
| 7216 | |
| 7217 | if (status == 0) |
| 7218 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7219 | |
| 7220 | if (cdata->xprt && status == 0) { |
| 7221 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7222 | cdata->xprt); |
| 7223 | goto out; |
| 7224 | } |
| 7225 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7226 | if (status == 0) |
| 7227 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7228 | |
| 7229 | if (status == 0) { |
| 7230 | clp->cl_clientid = cdata->res.clientid; |
| 7231 | clp->cl_exchange_flags = cdata->res.flags; |
| 7232 | /* Client ID is not confirmed */ |
| 7233 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7234 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7235 | &clp->cl_session->session_state); |
| 7236 | clp->cl_seqid = cdata->res.seqid; |
| 7237 | } |
| 7238 | |
| 7239 | kfree(clp->cl_serverowner); |
| 7240 | clp->cl_serverowner = cdata->res.server_owner; |
| 7241 | cdata->res.server_owner = NULL; |
| 7242 | |
| 7243 | /* use the most recent implementation id */ |
| 7244 | kfree(clp->cl_implid); |
| 7245 | clp->cl_implid = cdata->res.impl_id; |
| 7246 | cdata->res.impl_id = NULL; |
| 7247 | |
| 7248 | if (clp->cl_serverscope != NULL && |
| 7249 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7250 | cdata->res.server_scope)) { |
| 7251 | dprintk("%s: server_scope mismatch detected\n", |
| 7252 | __func__); |
| 7253 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7254 | kfree(clp->cl_serverscope); |
| 7255 | clp->cl_serverscope = NULL; |
| 7256 | } |
| 7257 | |
| 7258 | if (clp->cl_serverscope == NULL) { |
| 7259 | clp->cl_serverscope = cdata->res.server_scope; |
| 7260 | cdata->res.server_scope = NULL; |
| 7261 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7262 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7263 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7264 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7265 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7266 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7267 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7268 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | static void nfs4_exchange_id_release(void *data) |
| 7272 | { |
| 7273 | struct nfs41_exchange_id_data *cdata = |
| 7274 | (struct nfs41_exchange_id_data *)data; |
| 7275 | |
| 7276 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7277 | if (cdata->xprt) { |
| 7278 | xprt_put(cdata->xprt); |
| 7279 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7280 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7281 | kfree(cdata->res.impl_id); |
| 7282 | kfree(cdata->res.server_scope); |
| 7283 | kfree(cdata->res.server_owner); |
| 7284 | kfree(cdata); |
| 7285 | } |
| 7286 | |
| 7287 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7288 | .rpc_call_done = nfs4_exchange_id_done, |
| 7289 | .rpc_release = nfs4_exchange_id_release, |
| 7290 | }; |
| 7291 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7292 | /* |
| 7293 | * _nfs4_proc_exchange_id() |
| 7294 | * |
| 7295 | * Wrapper for EXCHANGE_ID operation. |
| 7296 | */ |
| 7297 | 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] | 7298 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7299 | { |
| 7300 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7301 | struct rpc_message msg = { |
| 7302 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7303 | .rpc_cred = cred, |
| 7304 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7305 | struct rpc_task_setup task_setup_data = { |
| 7306 | .rpc_client = clp->cl_rpcclient, |
| 7307 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7308 | .rpc_message = &msg, |
| 7309 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7310 | }; |
| 7311 | struct nfs41_exchange_id_data *calldata; |
| 7312 | struct rpc_task *task; |
| 7313 | int status = -EIO; |
| 7314 | |
| 7315 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7316 | goto out; |
| 7317 | |
| 7318 | status = -ENOMEM; |
| 7319 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7320 | if (!calldata) |
| 7321 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7322 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7323 | if (!xprt) |
| 7324 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7325 | |
| 7326 | status = nfs4_init_uniform_client_string(clp); |
| 7327 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7328 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7329 | |
| 7330 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7331 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7332 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7333 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7334 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7335 | GFP_NOFS); |
| 7336 | status = -ENOMEM; |
| 7337 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7338 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7339 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7340 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7341 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7342 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7343 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7344 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7345 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7346 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7347 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7348 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7349 | switch (sp4_how) { |
| 7350 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7351 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7352 | break; |
| 7353 | |
| 7354 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7355 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7356 | break; |
| 7357 | |
| 7358 | default: |
| 7359 | /* unsupported! */ |
| 7360 | WARN_ON_ONCE(1); |
| 7361 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7362 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7363 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7364 | if (xprt) { |
| 7365 | calldata->xprt = xprt; |
| 7366 | task_setup_data.rpc_xprt = xprt; |
| 7367 | task_setup_data.flags = |
| 7368 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7369 | calldata->args.verifier = &clp->cl_confirm; |
| 7370 | } else { |
| 7371 | calldata->args.verifier = &verifier; |
| 7372 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7373 | calldata->args.client = clp; |
| 7374 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7375 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7376 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7377 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7378 | #else |
| 7379 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7380 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7381 | #endif |
| 7382 | msg.rpc_argp = &calldata->args; |
| 7383 | msg.rpc_resp = &calldata->res; |
| 7384 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7385 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7386 | task = rpc_run_task(&task_setup_data); |
| 7387 | if (IS_ERR(task)) { |
| 7388 | status = PTR_ERR(task); |
| 7389 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7390 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7391 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7392 | if (!xprt) { |
| 7393 | status = rpc_wait_for_completion_task(task); |
| 7394 | if (!status) |
| 7395 | status = calldata->rpc_status; |
| 7396 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7397 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7398 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7399 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7400 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7401 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7402 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7403 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7404 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7405 | clp->cl_implid->date.seconds, |
| 7406 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7407 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7408 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7409 | |
| 7410 | out_impl_id: |
| 7411 | kfree(calldata->res.impl_id); |
| 7412 | out_server_scope: |
| 7413 | kfree(calldata->res.server_scope); |
| 7414 | out_server_owner: |
| 7415 | kfree(calldata->res.server_owner); |
| 7416 | out_calldata: |
| 7417 | kfree(calldata); |
| 7418 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7421 | /* |
| 7422 | * nfs4_proc_exchange_id() |
| 7423 | * |
| 7424 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7425 | * |
| 7426 | * Since the clientid has expired, all compounds using sessions |
| 7427 | * associated with the stale clientid will be returning |
| 7428 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7429 | * be in some phase of session reset. |
| 7430 | * |
| 7431 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7432 | */ |
| 7433 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7434 | { |
| 7435 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7436 | int status; |
| 7437 | |
| 7438 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7439 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7440 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7441 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7442 | if (!status) |
| 7443 | return 0; |
| 7444 | } |
| 7445 | |
| 7446 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7447 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7448 | } |
| 7449 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7450 | /** |
| 7451 | * nfs4_test_session_trunk |
| 7452 | * |
| 7453 | * This is an add_xprt_test() test function called from |
| 7454 | * rpc_clnt_setup_test_and_add_xprt. |
| 7455 | * |
| 7456 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7457 | * and is dereferrenced in nfs4_exchange_id_release |
| 7458 | * |
| 7459 | * Upon success, add the new transport to the rpc_clnt |
| 7460 | * |
| 7461 | * @clnt: struct rpc_clnt to get new transport |
| 7462 | * @xprt: the rpc_xprt to test |
| 7463 | * @data: call data for _nfs4_proc_exchange_id. |
| 7464 | */ |
| 7465 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7466 | void *data) |
| 7467 | { |
| 7468 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7469 | u32 sp4_how; |
| 7470 | |
| 7471 | dprintk("--> %s try %s\n", __func__, |
| 7472 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7473 | |
| 7474 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7475 | |
| 7476 | /* Test connection for session trunking. Async exchange_id call */ |
| 7477 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7478 | } |
| 7479 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7480 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7481 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7482 | struct rpc_cred *cred) |
| 7483 | { |
| 7484 | struct rpc_message msg = { |
| 7485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7486 | .rpc_argp = clp, |
| 7487 | .rpc_cred = cred, |
| 7488 | }; |
| 7489 | int status; |
| 7490 | |
| 7491 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7492 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7493 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7494 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7495 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7496 | return status; |
| 7497 | } |
| 7498 | |
| 7499 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7500 | struct rpc_cred *cred) |
| 7501 | { |
| 7502 | unsigned int loop; |
| 7503 | int ret; |
| 7504 | |
| 7505 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7506 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7507 | switch (ret) { |
| 7508 | case -NFS4ERR_DELAY: |
| 7509 | case -NFS4ERR_CLIENTID_BUSY: |
| 7510 | ssleep(1); |
| 7511 | break; |
| 7512 | default: |
| 7513 | return ret; |
| 7514 | } |
| 7515 | } |
| 7516 | return 0; |
| 7517 | } |
| 7518 | |
| 7519 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7520 | { |
| 7521 | struct rpc_cred *cred; |
| 7522 | int ret = 0; |
| 7523 | |
| 7524 | if (clp->cl_mvops->minor_version < 1) |
| 7525 | goto out; |
| 7526 | if (clp->cl_exchange_flags == 0) |
| 7527 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7528 | if (clp->cl_preserve_clid) |
| 7529 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7530 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7531 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7532 | if (cred) |
| 7533 | put_rpccred(cred); |
| 7534 | switch (ret) { |
| 7535 | case 0: |
| 7536 | case -NFS4ERR_STALE_CLIENTID: |
| 7537 | clp->cl_exchange_flags = 0; |
| 7538 | } |
| 7539 | out: |
| 7540 | return ret; |
| 7541 | } |
| 7542 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7543 | struct nfs4_get_lease_time_data { |
| 7544 | struct nfs4_get_lease_time_args *args; |
| 7545 | struct nfs4_get_lease_time_res *res; |
| 7546 | struct nfs_client *clp; |
| 7547 | }; |
| 7548 | |
| 7549 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7550 | void *calldata) |
| 7551 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7552 | struct nfs4_get_lease_time_data *data = |
| 7553 | (struct nfs4_get_lease_time_data *)calldata; |
| 7554 | |
| 7555 | dprintk("--> %s\n", __func__); |
| 7556 | /* just setup sequence, do not trigger session recovery |
| 7557 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7558 | nfs41_setup_sequence(data->clp->cl_session, |
| 7559 | &data->args->la_seq_args, |
| 7560 | &data->res->lr_seq_res, |
| 7561 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7562 | dprintk("<-- %s\n", __func__); |
| 7563 | } |
| 7564 | |
| 7565 | /* |
| 7566 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7567 | * from sequence operation or clientid errors. |
| 7568 | */ |
| 7569 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7570 | { |
| 7571 | struct nfs4_get_lease_time_data *data = |
| 7572 | (struct nfs4_get_lease_time_data *)calldata; |
| 7573 | |
| 7574 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7575 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7576 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7577 | switch (task->tk_status) { |
| 7578 | case -NFS4ERR_DELAY: |
| 7579 | case -NFS4ERR_GRACE: |
| 7580 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7581 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7582 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7583 | /* fall through */ |
| 7584 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7585 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7586 | return; |
| 7587 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7588 | dprintk("<-- %s\n", __func__); |
| 7589 | } |
| 7590 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7591 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7592 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7593 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7594 | }; |
| 7595 | |
| 7596 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7597 | { |
| 7598 | struct rpc_task *task; |
| 7599 | struct nfs4_get_lease_time_args args; |
| 7600 | struct nfs4_get_lease_time_res res = { |
| 7601 | .lr_fsinfo = fsinfo, |
| 7602 | }; |
| 7603 | struct nfs4_get_lease_time_data data = { |
| 7604 | .args = &args, |
| 7605 | .res = &res, |
| 7606 | .clp = clp, |
| 7607 | }; |
| 7608 | struct rpc_message msg = { |
| 7609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7610 | .rpc_argp = &args, |
| 7611 | .rpc_resp = &res, |
| 7612 | }; |
| 7613 | struct rpc_task_setup task_setup = { |
| 7614 | .rpc_client = clp->cl_rpcclient, |
| 7615 | .rpc_message = &msg, |
| 7616 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7617 | .callback_data = &data, |
| 7618 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7619 | }; |
| 7620 | int status; |
| 7621 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7622 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7623 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7624 | dprintk("--> %s\n", __func__); |
| 7625 | task = rpc_run_task(&task_setup); |
| 7626 | |
| 7627 | if (IS_ERR(task)) |
| 7628 | status = PTR_ERR(task); |
| 7629 | else { |
| 7630 | status = task->tk_status; |
| 7631 | rpc_put_task(task); |
| 7632 | } |
| 7633 | dprintk("<-- %s return %d\n", __func__, status); |
| 7634 | |
| 7635 | return status; |
| 7636 | } |
| 7637 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7638 | /* |
| 7639 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7640 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7641 | * use them. |
| 7642 | * |
| 7643 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7644 | * always set csa_cachethis to FALSE because the current implementation |
| 7645 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7646 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7647 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7648 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7649 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7650 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7651 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7652 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7653 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7654 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7655 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7656 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7657 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7658 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7659 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7660 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7661 | |
| 7662 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7663 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7664 | __func__, |
| 7665 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7666 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7667 | |
| 7668 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7669 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7670 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7671 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7672 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7673 | 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] | 7674 | |
| 7675 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7676 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7677 | __func__, |
| 7678 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7679 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7680 | args->bc_attrs.max_reqs); |
| 7681 | } |
| 7682 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7683 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7684 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7685 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7686 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7687 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7688 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7689 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7690 | return -EINVAL; |
| 7691 | /* |
| 7692 | * Our requested max_ops is the minimum we need; we're not |
| 7693 | * prepared to break up compounds into smaller pieces than that. |
| 7694 | * So, no point even trying to continue if the server won't |
| 7695 | * cooperate: |
| 7696 | */ |
| 7697 | if (rcvd->max_ops < sent->max_ops) |
| 7698 | return -EINVAL; |
| 7699 | if (rcvd->max_reqs == 0) |
| 7700 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7701 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7702 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7703 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7704 | } |
| 7705 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7706 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7707 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7708 | { |
| 7709 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7710 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7711 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7712 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7713 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7714 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7715 | return -EINVAL; |
| 7716 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7717 | return -EINVAL; |
| 7718 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7719 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7720 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7721 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7722 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7723 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7724 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7725 | return 0; |
| 7726 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7727 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7728 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7729 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7730 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7731 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7732 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7733 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7734 | if (ret) |
| 7735 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7736 | return nfs4_verify_back_channel_attrs(args, res); |
| 7737 | } |
| 7738 | |
| 7739 | static void nfs4_update_session(struct nfs4_session *session, |
| 7740 | struct nfs41_create_session_res *res) |
| 7741 | { |
| 7742 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7743 | /* Mark client id and session as being confirmed */ |
| 7744 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7745 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7746 | session->flags = res->flags; |
| 7747 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7748 | if (res->flags & SESSION4_BACK_CHAN) |
| 7749 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7750 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7751 | } |
| 7752 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7753 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7754 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7755 | { |
| 7756 | struct nfs4_session *session = clp->cl_session; |
| 7757 | struct nfs41_create_session_args args = { |
| 7758 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7759 | .clientid = clp->cl_clientid, |
| 7760 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7761 | .cb_program = NFS4_CALLBACK, |
| 7762 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7763 | struct nfs41_create_session_res res; |
| 7764 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7765 | struct rpc_message msg = { |
| 7766 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7767 | .rpc_argp = &args, |
| 7768 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7769 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7770 | }; |
| 7771 | int status; |
| 7772 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7773 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7774 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7775 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7776 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7777 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7778 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7779 | switch (status) { |
| 7780 | case -NFS4ERR_STALE_CLIENTID: |
| 7781 | case -NFS4ERR_DELAY: |
| 7782 | case -ETIMEDOUT: |
| 7783 | case -EACCES: |
| 7784 | case -EAGAIN: |
| 7785 | goto out; |
| 7786 | }; |
| 7787 | |
| 7788 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7789 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7790 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7791 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7792 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7793 | if (status) |
| 7794 | goto out; |
| 7795 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7796 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7797 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7798 | return status; |
| 7799 | } |
| 7800 | |
| 7801 | /* |
| 7802 | * Issues a CREATE_SESSION operation to the server. |
| 7803 | * It is the responsibility of the caller to verify the session is |
| 7804 | * expired before calling this routine. |
| 7805 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7806 | 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] | 7807 | { |
| 7808 | int status; |
| 7809 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7810 | struct nfs4_session *session = clp->cl_session; |
| 7811 | |
| 7812 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7813 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7814 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7815 | if (status) |
| 7816 | goto out; |
| 7817 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7818 | /* Init or reset the session slot tables */ |
| 7819 | status = nfs4_setup_session_slot_tables(session); |
| 7820 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7821 | if (status) |
| 7822 | goto out; |
| 7823 | |
| 7824 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7825 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7826 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7827 | out: |
| 7828 | dprintk("<-- %s\n", __func__); |
| 7829 | return status; |
| 7830 | } |
| 7831 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7832 | /* |
| 7833 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7834 | * The caller must serialize access to this routine. |
| 7835 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7836 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7837 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7838 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7839 | struct rpc_message msg = { |
| 7840 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7841 | .rpc_argp = session, |
| 7842 | .rpc_cred = cred, |
| 7843 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7844 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7845 | |
| 7846 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7847 | |
| 7848 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7849 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7850 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7851 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7852 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7853 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7854 | |
| 7855 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7856 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7857 | "Session has been destroyed regardless...\n", status); |
| 7858 | |
| 7859 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7860 | return status; |
| 7861 | } |
| 7862 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7863 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7864 | * Renew the cl_session lease. |
| 7865 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7866 | struct nfs4_sequence_data { |
| 7867 | struct nfs_client *clp; |
| 7868 | struct nfs4_sequence_args args; |
| 7869 | struct nfs4_sequence_res res; |
| 7870 | }; |
| 7871 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7872 | static void nfs41_sequence_release(void *data) |
| 7873 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7874 | struct nfs4_sequence_data *calldata = data; |
| 7875 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7876 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7877 | if (atomic_read(&clp->cl_count) > 1) |
| 7878 | nfs4_schedule_state_renewal(clp); |
| 7879 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7880 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7881 | } |
| 7882 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7883 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7884 | { |
| 7885 | switch(task->tk_status) { |
| 7886 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7887 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7888 | return -EAGAIN; |
| 7889 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7890 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7891 | } |
| 7892 | return 0; |
| 7893 | } |
| 7894 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7895 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7896 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7897 | struct nfs4_sequence_data *calldata = data; |
| 7898 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7899 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7900 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7901 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7902 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7903 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7904 | if (task->tk_status < 0) { |
| 7905 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7906 | if (atomic_read(&clp->cl_count) == 1) |
| 7907 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7908 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7909 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7910 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7911 | return; |
| 7912 | } |
| 7913 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7914 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7915 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7916 | dprintk("<-- %s\n", __func__); |
| 7917 | } |
| 7918 | |
| 7919 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7920 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7921 | struct nfs4_sequence_data *calldata = data; |
| 7922 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7923 | struct nfs4_sequence_args *args; |
| 7924 | struct nfs4_sequence_res *res; |
| 7925 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7926 | args = task->tk_msg.rpc_argp; |
| 7927 | res = task->tk_msg.rpc_resp; |
| 7928 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7929 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7930 | } |
| 7931 | |
| 7932 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7933 | .rpc_call_done = nfs41_sequence_call_done, |
| 7934 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7935 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7936 | }; |
| 7937 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7938 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7939 | struct rpc_cred *cred, |
| 7940 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7941 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7942 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7943 | struct rpc_message msg = { |
| 7944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7945 | .rpc_cred = cred, |
| 7946 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7947 | struct rpc_task_setup task_setup_data = { |
| 7948 | .rpc_client = clp->cl_rpcclient, |
| 7949 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7950 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7951 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7952 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7953 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7954 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7955 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7956 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7957 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7958 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7959 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7960 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7961 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7962 | if (is_privileged) |
| 7963 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7964 | msg.rpc_argp = &calldata->args; |
| 7965 | msg.rpc_resp = &calldata->res; |
| 7966 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7967 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7968 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7969 | return rpc_run_task(&task_setup_data); |
| 7970 | } |
| 7971 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7972 | 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] | 7973 | { |
| 7974 | struct rpc_task *task; |
| 7975 | int ret = 0; |
| 7976 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7977 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7978 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7979 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7980 | if (IS_ERR(task)) |
| 7981 | ret = PTR_ERR(task); |
| 7982 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7983 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7984 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7985 | return ret; |
| 7986 | } |
| 7987 | |
| 7988 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7989 | { |
| 7990 | struct rpc_task *task; |
| 7991 | int ret; |
| 7992 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7993 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7994 | if (IS_ERR(task)) { |
| 7995 | ret = PTR_ERR(task); |
| 7996 | goto out; |
| 7997 | } |
| 7998 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 7999 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8000 | ret = task->tk_status; |
| 8001 | rpc_put_task(task); |
| 8002 | out: |
| 8003 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8004 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8005 | } |
| 8006 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8007 | struct nfs4_reclaim_complete_data { |
| 8008 | struct nfs_client *clp; |
| 8009 | struct nfs41_reclaim_complete_args arg; |
| 8010 | struct nfs41_reclaim_complete_res res; |
| 8011 | }; |
| 8012 | |
| 8013 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8014 | { |
| 8015 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8016 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8017 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8018 | &calldata->arg.seq_args, |
| 8019 | &calldata->res.seq_res, |
| 8020 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8021 | } |
| 8022 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8023 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8024 | { |
| 8025 | switch(task->tk_status) { |
| 8026 | case 0: |
| 8027 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8028 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8029 | break; |
| 8030 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8031 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8032 | /* fall through */ |
| 8033 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8034 | return -EAGAIN; |
| 8035 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8036 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8037 | } |
| 8038 | return 0; |
| 8039 | } |
| 8040 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8041 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8042 | { |
| 8043 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8044 | struct nfs_client *clp = calldata->clp; |
| 8045 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8046 | |
| 8047 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8048 | if (!nfs41_sequence_done(task, res)) |
| 8049 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8050 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8051 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8052 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8053 | rpc_restart_call_prepare(task); |
| 8054 | return; |
| 8055 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8056 | dprintk("<-- %s\n", __func__); |
| 8057 | } |
| 8058 | |
| 8059 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8060 | { |
| 8061 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8062 | |
| 8063 | kfree(calldata); |
| 8064 | } |
| 8065 | |
| 8066 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8067 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8068 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8069 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8070 | }; |
| 8071 | |
| 8072 | /* |
| 8073 | * Issue a global reclaim complete. |
| 8074 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8075 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8076 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8077 | { |
| 8078 | struct nfs4_reclaim_complete_data *calldata; |
| 8079 | struct rpc_task *task; |
| 8080 | struct rpc_message msg = { |
| 8081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8082 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8083 | }; |
| 8084 | struct rpc_task_setup task_setup_data = { |
| 8085 | .rpc_client = clp->cl_rpcclient, |
| 8086 | .rpc_message = &msg, |
| 8087 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8088 | .flags = RPC_TASK_ASYNC, |
| 8089 | }; |
| 8090 | int status = -ENOMEM; |
| 8091 | |
| 8092 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8093 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8094 | if (calldata == NULL) |
| 8095 | goto out; |
| 8096 | calldata->clp = clp; |
| 8097 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8098 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8099 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8100 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8101 | msg.rpc_argp = &calldata->arg; |
| 8102 | msg.rpc_resp = &calldata->res; |
| 8103 | task_setup_data.callback_data = calldata; |
| 8104 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8105 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8106 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8107 | goto out; |
| 8108 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8109 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8110 | if (status == 0) |
| 8111 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8112 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8113 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8114 | out: |
| 8115 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8116 | return status; |
| 8117 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8118 | |
| 8119 | static void |
| 8120 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8121 | { |
| 8122 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8123 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8124 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8125 | |
| 8126 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8127 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8128 | &lgp->res.seq_res, task); |
| 8129 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8133 | { |
| 8134 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8135 | |
| 8136 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8137 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8138 | dprintk("<-- %s\n", __func__); |
| 8139 | } |
| 8140 | |
| 8141 | static int |
| 8142 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8143 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8144 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8145 | struct inode *inode = lgp->args.inode; |
| 8146 | struct nfs_server *server = NFS_SERVER(inode); |
| 8147 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8148 | int nfs4err = task->tk_status; |
| 8149 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8150 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8151 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8152 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8153 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8154 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8155 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8156 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8157 | |
| 8158 | /* |
| 8159 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8160 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8161 | * retry go inband. |
| 8162 | */ |
| 8163 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8164 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8165 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8166 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8167 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8168 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8169 | */ |
| 8170 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8171 | status = -EOVERFLOW; |
| 8172 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8173 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8174 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8175 | * (or clients) writing to the same RAID stripe except when |
| 8176 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8177 | * |
| 8178 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8179 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8180 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8181 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8182 | if (lgp->args.minlength == 0) { |
| 8183 | status = -EOVERFLOW; |
| 8184 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8185 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8186 | status = -EBUSY; |
| 8187 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8188 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8189 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8190 | break; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8191 | case -NFS4ERR_EXPIRED: |
| 8192 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8193 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8194 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8195 | lo = NFS_I(inode)->layout; |
| 8196 | /* If the open stateid was bad, then recover it. */ |
| 8197 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8198 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8199 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8200 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8201 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8202 | break; |
| 8203 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8204 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8205 | /* |
| 8206 | * Mark the bad layout state as invalid, then retry |
| 8207 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8208 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8209 | spin_unlock(&inode->i_lock); |
| 8210 | pnfs_free_lseg_list(&head); |
| 8211 | status = -EAGAIN; |
| 8212 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8213 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8214 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8215 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8216 | if (!status) { |
| 8217 | if (exception->retry) |
| 8218 | status = -EAGAIN; |
| 8219 | else |
| 8220 | status = err; |
| 8221 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8222 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8223 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8224 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8225 | } |
| 8226 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8227 | static size_t max_response_pages(struct nfs_server *server) |
| 8228 | { |
| 8229 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8230 | return nfs_page_array_len(0, max_resp_sz); |
| 8231 | } |
| 8232 | |
| 8233 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8234 | { |
| 8235 | int i; |
| 8236 | |
| 8237 | if (!pages) |
| 8238 | return; |
| 8239 | |
| 8240 | for (i = 0; i < size; i++) { |
| 8241 | if (!pages[i]) |
| 8242 | break; |
| 8243 | __free_page(pages[i]); |
| 8244 | } |
| 8245 | kfree(pages); |
| 8246 | } |
| 8247 | |
| 8248 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8249 | { |
| 8250 | struct page **pages; |
| 8251 | int i; |
| 8252 | |
| 8253 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8254 | if (!pages) { |
| 8255 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8256 | return NULL; |
| 8257 | } |
| 8258 | |
| 8259 | for (i = 0; i < size; i++) { |
| 8260 | pages[i] = alloc_page(gfp_flags); |
| 8261 | if (!pages[i]) { |
| 8262 | dprintk("%s: failed to allocate page\n", __func__); |
| 8263 | nfs4_free_pages(pages, size); |
| 8264 | return NULL; |
| 8265 | } |
| 8266 | } |
| 8267 | |
| 8268 | return pages; |
| 8269 | } |
| 8270 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8271 | static void nfs4_layoutget_release(void *calldata) |
| 8272 | { |
| 8273 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8274 | struct inode *inode = lgp->args.inode; |
| 8275 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8276 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8277 | |
| 8278 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8279 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8280 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8281 | put_nfs_open_context(lgp->args.ctx); |
| 8282 | kfree(calldata); |
| 8283 | dprintk("<-- %s\n", __func__); |
| 8284 | } |
| 8285 | |
| 8286 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8287 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8288 | .rpc_call_done = nfs4_layoutget_done, |
| 8289 | .rpc_release = nfs4_layoutget_release, |
| 8290 | }; |
| 8291 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8292 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8293 | 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] | 8294 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8295 | struct inode *inode = lgp->args.inode; |
| 8296 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8297 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8298 | struct rpc_task *task; |
| 8299 | struct rpc_message msg = { |
| 8300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8301 | .rpc_argp = &lgp->args, |
| 8302 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8303 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8304 | }; |
| 8305 | struct rpc_task_setup task_setup_data = { |
| 8306 | .rpc_client = server->client, |
| 8307 | .rpc_message = &msg, |
| 8308 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8309 | .callback_data = lgp, |
| 8310 | .flags = RPC_TASK_ASYNC, |
| 8311 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8312 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8313 | struct nfs4_exception exception = { |
| 8314 | .inode = inode, |
| 8315 | .timeout = *timeout, |
| 8316 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8317 | int status = 0; |
| 8318 | |
| 8319 | dprintk("--> %s\n", __func__); |
| 8320 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8321 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8322 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8323 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8324 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8325 | if (!lgp->args.layout.pages) { |
| 8326 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8327 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8328 | } |
| 8329 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8330 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8331 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8332 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8333 | 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] | 8334 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8335 | task = rpc_run_task(&task_setup_data); |
| 8336 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8337 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8338 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8339 | if (status == 0) { |
| 8340 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8341 | *timeout = exception.timeout; |
| 8342 | } |
| 8343 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8344 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8345 | &lgp->args.range, |
| 8346 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8347 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8348 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8349 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8350 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8351 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8352 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8353 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8354 | rpc_put_task(task); |
| 8355 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8356 | if (status) |
| 8357 | return ERR_PTR(status); |
| 8358 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8359 | } |
| 8360 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8361 | static void |
| 8362 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8363 | { |
| 8364 | struct nfs4_layoutreturn *lrp = calldata; |
| 8365 | |
| 8366 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8367 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8368 | &lrp->args.seq_args, |
| 8369 | &lrp->res.seq_res, |
| 8370 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8374 | { |
| 8375 | struct nfs4_layoutreturn *lrp = calldata; |
| 8376 | struct nfs_server *server; |
| 8377 | |
| 8378 | dprintk("--> %s\n", __func__); |
| 8379 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8380 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8381 | return; |
| 8382 | |
| 8383 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8384 | switch (task->tk_status) { |
| 8385 | default: |
| 8386 | task->tk_status = 0; |
| 8387 | case 0: |
| 8388 | break; |
| 8389 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8390 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8391 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8392 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8393 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8394 | return; |
| 8395 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8396 | dprintk("<-- %s\n", __func__); |
| 8397 | } |
| 8398 | |
| 8399 | static void nfs4_layoutreturn_release(void *calldata) |
| 8400 | { |
| 8401 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8402 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8403 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8404 | |
| 8405 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8406 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8407 | if (lrp->res.lrs_present) { |
| 8408 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8409 | &lrp->args.range, |
| 8410 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8411 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8412 | } else |
| 8413 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8414 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8415 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8416 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8417 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8418 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8419 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8420 | kfree(calldata); |
| 8421 | dprintk("<-- %s\n", __func__); |
| 8422 | } |
| 8423 | |
| 8424 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8425 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8426 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8427 | .rpc_release = nfs4_layoutreturn_release, |
| 8428 | }; |
| 8429 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8430 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8431 | { |
| 8432 | struct rpc_task *task; |
| 8433 | struct rpc_message msg = { |
| 8434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8435 | .rpc_argp = &lrp->args, |
| 8436 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8437 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8438 | }; |
| 8439 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8440 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8441 | .rpc_message = &msg, |
| 8442 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8443 | .callback_data = lrp, |
| 8444 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8445 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8446 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8447 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8448 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8449 | &task_setup_data.rpc_client, &msg); |
| 8450 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8451 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8452 | if (!sync) { |
| 8453 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8454 | if (!lrp->inode) { |
| 8455 | nfs4_layoutreturn_release(lrp); |
| 8456 | return -EAGAIN; |
| 8457 | } |
| 8458 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8459 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8460 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8461 | task = rpc_run_task(&task_setup_data); |
| 8462 | if (IS_ERR(task)) |
| 8463 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8464 | if (sync) |
| 8465 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8466 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8467 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8468 | rpc_put_task(task); |
| 8469 | return status; |
| 8470 | } |
| 8471 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8472 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8473 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8474 | struct pnfs_device *pdev, |
| 8475 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8476 | { |
| 8477 | struct nfs4_getdeviceinfo_args args = { |
| 8478 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8479 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8480 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8481 | }; |
| 8482 | struct nfs4_getdeviceinfo_res res = { |
| 8483 | .pdev = pdev, |
| 8484 | }; |
| 8485 | struct rpc_message msg = { |
| 8486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8487 | .rpc_argp = &args, |
| 8488 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8489 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8490 | }; |
| 8491 | int status; |
| 8492 | |
| 8493 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8494 | 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] | 8495 | if (res.notification & ~args.notify_types) |
| 8496 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8497 | if (res.notification != args.notify_types) |
| 8498 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8499 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8500 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8501 | |
| 8502 | return status; |
| 8503 | } |
| 8504 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8505 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8506 | struct pnfs_device *pdev, |
| 8507 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8508 | { |
| 8509 | struct nfs4_exception exception = { }; |
| 8510 | int err; |
| 8511 | |
| 8512 | do { |
| 8513 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8514 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8515 | &exception); |
| 8516 | } while (exception.retry); |
| 8517 | return err; |
| 8518 | } |
| 8519 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8520 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8521 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8522 | { |
| 8523 | struct nfs4_layoutcommit_data *data = calldata; |
| 8524 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8525 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8526 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8527 | nfs41_setup_sequence(session, |
| 8528 | &data->args.seq_args, |
| 8529 | &data->res.seq_res, |
| 8530 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | static void |
| 8534 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8535 | { |
| 8536 | struct nfs4_layoutcommit_data *data = calldata; |
| 8537 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8538 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8539 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8540 | return; |
| 8541 | |
| 8542 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8543 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8544 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8545 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8546 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8547 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8548 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8549 | break; |
| 8550 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8551 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8552 | rpc_restart_call_prepare(task); |
| 8553 | return; |
| 8554 | } |
| 8555 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8556 | } |
| 8557 | |
| 8558 | static void nfs4_layoutcommit_release(void *calldata) |
| 8559 | { |
| 8560 | struct nfs4_layoutcommit_data *data = calldata; |
| 8561 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8562 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8563 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8564 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8565 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8566 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8567 | kfree(data); |
| 8568 | } |
| 8569 | |
| 8570 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8571 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8572 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8573 | .rpc_release = nfs4_layoutcommit_release, |
| 8574 | }; |
| 8575 | |
| 8576 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8577 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8578 | { |
| 8579 | struct rpc_message msg = { |
| 8580 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8581 | .rpc_argp = &data->args, |
| 8582 | .rpc_resp = &data->res, |
| 8583 | .rpc_cred = data->cred, |
| 8584 | }; |
| 8585 | struct rpc_task_setup task_setup_data = { |
| 8586 | .task = &data->task, |
| 8587 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8588 | .rpc_message = &msg, |
| 8589 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8590 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8591 | }; |
| 8592 | struct rpc_task *task; |
| 8593 | int status = 0; |
| 8594 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8595 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8596 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8597 | data->args.lastbytewritten, |
| 8598 | data->args.inode->i_ino); |
| 8599 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8600 | if (!sync) { |
| 8601 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8602 | if (data->inode == NULL) { |
| 8603 | nfs4_layoutcommit_release(data); |
| 8604 | return -EAGAIN; |
| 8605 | } |
| 8606 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8607 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8608 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8609 | task = rpc_run_task(&task_setup_data); |
| 8610 | if (IS_ERR(task)) |
| 8611 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8612 | if (sync) |
| 8613 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8614 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8615 | dprintk("%s: status %d\n", __func__, status); |
| 8616 | rpc_put_task(task); |
| 8617 | return status; |
| 8618 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8619 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8620 | /** |
| 8621 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8622 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8623 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8624 | static int |
| 8625 | _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] | 8626 | struct nfs_fsinfo *info, |
| 8627 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8628 | { |
| 8629 | struct nfs41_secinfo_no_name_args args = { |
| 8630 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8631 | }; |
| 8632 | struct nfs4_secinfo_res res = { |
| 8633 | .flavors = flavors, |
| 8634 | }; |
| 8635 | struct rpc_message msg = { |
| 8636 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8637 | .rpc_argp = &args, |
| 8638 | .rpc_resp = &res, |
| 8639 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8640 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8641 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8642 | int status; |
| 8643 | |
| 8644 | if (use_integrity) { |
| 8645 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8646 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8647 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8648 | } |
| 8649 | |
| 8650 | dprintk("--> %s\n", __func__); |
| 8651 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8652 | &res.seq_res, 0); |
| 8653 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8654 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8655 | if (cred) |
| 8656 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8657 | |
| 8658 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8659 | } |
| 8660 | |
| 8661 | static int |
| 8662 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8663 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8664 | { |
| 8665 | struct nfs4_exception exception = { }; |
| 8666 | int err; |
| 8667 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8668 | /* first try using integrity protection */ |
| 8669 | err = -NFS4ERR_WRONGSEC; |
| 8670 | |
| 8671 | /* try to use integrity protection with machine cred */ |
| 8672 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8673 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8674 | flavors, true); |
| 8675 | |
| 8676 | /* |
| 8677 | * if unable to use integrity protection, or SECINFO with |
| 8678 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8679 | * disallowed by spec, but exists in deployed servers) use |
| 8680 | * the current filesystem's rpc_client and the user cred. |
| 8681 | */ |
| 8682 | if (err == -NFS4ERR_WRONGSEC) |
| 8683 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8684 | flavors, false); |
| 8685 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8686 | switch (err) { |
| 8687 | case 0: |
| 8688 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8689 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8690 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8691 | default: |
| 8692 | err = nfs4_handle_exception(server, err, &exception); |
| 8693 | } |
| 8694 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8695 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8696 | return err; |
| 8697 | } |
| 8698 | |
| 8699 | static int |
| 8700 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8701 | struct nfs_fsinfo *info) |
| 8702 | { |
| 8703 | int err; |
| 8704 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8705 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8706 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8707 | struct nfs4_secinfo4 *secinfo; |
| 8708 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8709 | |
| 8710 | page = alloc_page(GFP_KERNEL); |
| 8711 | if (!page) { |
| 8712 | err = -ENOMEM; |
| 8713 | goto out; |
| 8714 | } |
| 8715 | |
| 8716 | flavors = page_address(page); |
| 8717 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8718 | |
| 8719 | /* |
| 8720 | * Fall back on "guess and check" method if |
| 8721 | * the server doesn't support SECINFO_NO_NAME |
| 8722 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8723 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8724 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8725 | goto out_freepage; |
| 8726 | } |
| 8727 | if (err) |
| 8728 | goto out_freepage; |
| 8729 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8730 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8731 | secinfo = &flavors->flavors[i]; |
| 8732 | |
| 8733 | switch (secinfo->flavor) { |
| 8734 | case RPC_AUTH_NULL: |
| 8735 | case RPC_AUTH_UNIX: |
| 8736 | case RPC_AUTH_GSS: |
| 8737 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8738 | &secinfo->flavor_info); |
| 8739 | break; |
| 8740 | default: |
| 8741 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8742 | break; |
| 8743 | } |
| 8744 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8745 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8746 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8747 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8748 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8749 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8750 | info, flavor); |
| 8751 | if (!err) |
| 8752 | break; |
| 8753 | } |
| 8754 | } |
| 8755 | |
| 8756 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8757 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8758 | |
| 8759 | out_freepage: |
| 8760 | put_page(page); |
| 8761 | if (err == -EACCES) |
| 8762 | return -EPERM; |
| 8763 | out: |
| 8764 | return err; |
| 8765 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8766 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8767 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8768 | nfs4_stateid *stateid, |
| 8769 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8770 | { |
| 8771 | int status; |
| 8772 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8773 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8774 | }; |
| 8775 | struct nfs41_test_stateid_res res; |
| 8776 | struct rpc_message msg = { |
| 8777 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8778 | .rpc_argp = &args, |
| 8779 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8780 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8781 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8782 | struct rpc_clnt *rpc_client = server->client; |
| 8783 | |
| 8784 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8785 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8786 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8787 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8788 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8789 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8790 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8791 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8792 | if (status != NFS_OK) { |
| 8793 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8794 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8795 | } |
| 8796 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8797 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8798 | } |
| 8799 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame^] | 8800 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8801 | int err, struct nfs4_exception *exception) |
| 8802 | { |
| 8803 | exception->retry = 0; |
| 8804 | switch(err) { |
| 8805 | case -NFS4ERR_DELAY: |
| 8806 | nfs4_handle_exception(server, err, exception); |
| 8807 | break; |
| 8808 | case -NFS4ERR_BADSESSION: |
| 8809 | case -NFS4ERR_BADSLOT: |
| 8810 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8811 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8812 | case -NFS4ERR_DEADSESSION: |
| 8813 | nfs4_do_handle_exception(server, err, exception); |
| 8814 | } |
| 8815 | } |
| 8816 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8817 | /** |
| 8818 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8819 | * |
| 8820 | * @server: server / transport on which to perform the operation |
| 8821 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8822 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8823 | * |
| 8824 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8825 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8826 | * failed or the state ID is not currently valid. |
| 8827 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8828 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8829 | nfs4_stateid *stateid, |
| 8830 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8831 | { |
| 8832 | struct nfs4_exception exception = { }; |
| 8833 | int err; |
| 8834 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8835 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame^] | 8836 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8837 | } while (exception.retry); |
| 8838 | return err; |
| 8839 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8840 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8841 | struct nfs_free_stateid_data { |
| 8842 | struct nfs_server *server; |
| 8843 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8844 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8845 | }; |
| 8846 | |
| 8847 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8848 | { |
| 8849 | struct nfs_free_stateid_data *data = calldata; |
| 8850 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8851 | &data->args.seq_args, |
| 8852 | &data->res.seq_res, |
| 8853 | task); |
| 8854 | } |
| 8855 | |
| 8856 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8857 | { |
| 8858 | struct nfs_free_stateid_data *data = calldata; |
| 8859 | |
| 8860 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8861 | |
| 8862 | switch (task->tk_status) { |
| 8863 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8864 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8865 | rpc_restart_call_prepare(task); |
| 8866 | } |
| 8867 | } |
| 8868 | |
| 8869 | static void nfs41_free_stateid_release(void *calldata) |
| 8870 | { |
| 8871 | kfree(calldata); |
| 8872 | } |
| 8873 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8874 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8875 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8876 | .rpc_call_done = nfs41_free_stateid_done, |
| 8877 | .rpc_release = nfs41_free_stateid_release, |
| 8878 | }; |
| 8879 | |
| 8880 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8881 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8882 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8883 | bool privileged) |
| 8884 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8885 | struct rpc_message msg = { |
| 8886 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8887 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8888 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8889 | struct rpc_task_setup task_setup = { |
| 8890 | .rpc_client = server->client, |
| 8891 | .rpc_message = &msg, |
| 8892 | .callback_ops = &nfs41_free_stateid_ops, |
| 8893 | .flags = RPC_TASK_ASYNC, |
| 8894 | }; |
| 8895 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8896 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8897 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8898 | &task_setup.rpc_client, &msg); |
| 8899 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8900 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8901 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8902 | if (!data) |
| 8903 | return ERR_PTR(-ENOMEM); |
| 8904 | data->server = server; |
| 8905 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8906 | |
| 8907 | task_setup.callback_data = data; |
| 8908 | |
| 8909 | msg.rpc_argp = &data->args; |
| 8910 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8911 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8912 | if (privileged) |
| 8913 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8914 | |
| 8915 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8916 | } |
| 8917 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8918 | /** |
| 8919 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8920 | * |
| 8921 | * @server: server / transport on which to perform the operation |
| 8922 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8923 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8924 | * |
| 8925 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8926 | * negative NFS4ERR value is returned. |
| 8927 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8928 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8929 | nfs4_stateid *stateid, |
| 8930 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8931 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8932 | struct rpc_task *task; |
| 8933 | int ret; |
| 8934 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8935 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8936 | if (IS_ERR(task)) |
| 8937 | return PTR_ERR(task); |
| 8938 | ret = rpc_wait_for_completion_task(task); |
| 8939 | if (!ret) |
| 8940 | ret = task->tk_status; |
| 8941 | rpc_put_task(task); |
| 8942 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8943 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8944 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8945 | static void |
| 8946 | 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] | 8947 | { |
| 8948 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8949 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8950 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8951 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8952 | nfs4_free_lock_state(server, lsp); |
| 8953 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8954 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8955 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8956 | } |
| 8957 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8958 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8959 | const nfs4_stateid *s2) |
| 8960 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8961 | if (s1->type != s2->type) |
| 8962 | return false; |
| 8963 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8964 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8965 | return false; |
| 8966 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8967 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8968 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8969 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8970 | return true; |
| 8971 | |
| 8972 | return false; |
| 8973 | } |
| 8974 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8975 | #endif /* CONFIG_NFS_V4_1 */ |
| 8976 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8977 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8978 | const nfs4_stateid *s2) |
| 8979 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8980 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8981 | } |
| 8982 | |
| 8983 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8984 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8985 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8986 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8987 | .recover_open = nfs4_open_reclaim, |
| 8988 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8989 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8990 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8991 | }; |
| 8992 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8993 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8994 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8995 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8996 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8997 | .recover_open = nfs4_open_reclaim, |
| 8998 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8999 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9000 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9001 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9002 | }; |
| 9003 | #endif /* CONFIG_NFS_V4_1 */ |
| 9004 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9005 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9006 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9007 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9008 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9009 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9010 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9011 | }; |
| 9012 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9013 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9014 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9015 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9016 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9017 | .recover_open = nfs41_open_expired, |
| 9018 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9019 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9020 | }; |
| 9021 | #endif /* CONFIG_NFS_V4_1 */ |
| 9022 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9023 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9024 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9025 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9026 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9027 | }; |
| 9028 | |
| 9029 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9030 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9031 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9032 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9033 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9034 | }; |
| 9035 | #endif |
| 9036 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9037 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9038 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9039 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9040 | }; |
| 9041 | |
| 9042 | #if defined(CONFIG_NFS_V4_1) |
| 9043 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9044 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9045 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9046 | }; |
| 9047 | #endif /* CONFIG_NFS_V4_1 */ |
| 9048 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9049 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9050 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9051 | .init_caps = NFS_CAP_READDIRPLUS |
| 9052 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9053 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9054 | .init_client = nfs40_init_client, |
| 9055 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9056 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9057 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9058 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9059 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9060 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9061 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9062 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9063 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9064 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9065 | }; |
| 9066 | |
| 9067 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9068 | static struct nfs_seqid * |
| 9069 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9070 | { |
| 9071 | return NULL; |
| 9072 | } |
| 9073 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9074 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9075 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9076 | .init_caps = NFS_CAP_READDIRPLUS |
| 9077 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9078 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9079 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9080 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9081 | .init_client = nfs41_init_client, |
| 9082 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9083 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9084 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9085 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9086 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9087 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9088 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9089 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9090 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9091 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9092 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9093 | }; |
| 9094 | #endif |
| 9095 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9096 | #if defined(CONFIG_NFS_V4_2) |
| 9097 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9098 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9099 | .init_caps = NFS_CAP_READDIRPLUS |
| 9100 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9101 | | NFS_CAP_POSIX_LOCK |
| 9102 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9103 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9104 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9105 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9106 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9107 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9108 | | NFS_CAP_LAYOUTSTATS |
| 9109 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9110 | .init_client = nfs41_init_client, |
| 9111 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9112 | .match_stateid = nfs41_match_stateid, |
| 9113 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9114 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9115 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9116 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9117 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9118 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9119 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9120 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9121 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9122 | }; |
| 9123 | #endif |
| 9124 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9125 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9126 | [0] = &nfs_v4_0_minor_ops, |
| 9127 | #if defined(CONFIG_NFS_V4_1) |
| 9128 | [1] = &nfs_v4_1_minor_ops, |
| 9129 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9130 | #if defined(CONFIG_NFS_V4_2) |
| 9131 | [2] = &nfs_v4_2_minor_ops, |
| 9132 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9133 | }; |
| 9134 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9135 | 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] | 9136 | { |
| 9137 | ssize_t error, error2; |
| 9138 | |
| 9139 | error = generic_listxattr(dentry, list, size); |
| 9140 | if (error < 0) |
| 9141 | return error; |
| 9142 | if (list) { |
| 9143 | list += error; |
| 9144 | size -= error; |
| 9145 | } |
| 9146 | |
| 9147 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9148 | if (error2 < 0) |
| 9149 | return error2; |
| 9150 | return error + error2; |
| 9151 | } |
| 9152 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9153 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9154 | .create = nfs_create, |
| 9155 | .lookup = nfs_lookup, |
| 9156 | .atomic_open = nfs_atomic_open, |
| 9157 | .link = nfs_link, |
| 9158 | .unlink = nfs_unlink, |
| 9159 | .symlink = nfs_symlink, |
| 9160 | .mkdir = nfs_mkdir, |
| 9161 | .rmdir = nfs_rmdir, |
| 9162 | .mknod = nfs_mknod, |
| 9163 | .rename = nfs_rename, |
| 9164 | .permission = nfs_permission, |
| 9165 | .getattr = nfs_getattr, |
| 9166 | .setattr = nfs_setattr, |
| 9167 | .getxattr = generic_getxattr, |
| 9168 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9169 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9170 | .removexattr = generic_removexattr, |
| 9171 | }; |
| 9172 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9173 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9174 | .permission = nfs_permission, |
| 9175 | .getattr = nfs_getattr, |
| 9176 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9177 | .getxattr = generic_getxattr, |
| 9178 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9179 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9180 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9181 | }; |
| 9182 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9183 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9184 | .version = 4, /* protocol version */ |
| 9185 | .dentry_ops = &nfs4_dentry_operations, |
| 9186 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9187 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9188 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9189 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9190 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9191 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9192 | .getattr = nfs4_proc_getattr, |
| 9193 | .setattr = nfs4_proc_setattr, |
| 9194 | .lookup = nfs4_proc_lookup, |
| 9195 | .access = nfs4_proc_access, |
| 9196 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9197 | .create = nfs4_proc_create, |
| 9198 | .remove = nfs4_proc_remove, |
| 9199 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9200 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9201 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9202 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9203 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9204 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9205 | .link = nfs4_proc_link, |
| 9206 | .symlink = nfs4_proc_symlink, |
| 9207 | .mkdir = nfs4_proc_mkdir, |
| 9208 | .rmdir = nfs4_proc_remove, |
| 9209 | .readdir = nfs4_proc_readdir, |
| 9210 | .mknod = nfs4_proc_mknod, |
| 9211 | .statfs = nfs4_proc_statfs, |
| 9212 | .fsinfo = nfs4_proc_fsinfo, |
| 9213 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9214 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9215 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9216 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9217 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9218 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9219 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9220 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9221 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9222 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9223 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9224 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9225 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9226 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9227 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9228 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9229 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9230 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9231 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9232 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9233 | .create_server = nfs4_create_server, |
| 9234 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9235 | }; |
| 9236 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9237 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9238 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9239 | .list = nfs4_xattr_list_nfs4_acl, |
| 9240 | .get = nfs4_xattr_get_nfs4_acl, |
| 9241 | .set = nfs4_xattr_set_nfs4_acl, |
| 9242 | }; |
| 9243 | |
| 9244 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9245 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9246 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9247 | &nfs4_xattr_nfs4_label_handler, |
| 9248 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9249 | NULL |
| 9250 | }; |
| 9251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9252 | /* |
| 9253 | * Local variables: |
| 9254 | * c-basic-offset: 8 |
| 9255 | * End: |
| 9256 | */ |