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 | |
| 619 | args->sa_slot = slot; |
| 620 | res->sr_slot = slot; |
| 621 | |
| 622 | out_start: |
| 623 | rpc_call_start(task); |
| 624 | return 0; |
| 625 | |
| 626 | out_sleep: |
| 627 | if (args->sa_privileged) |
| 628 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 629 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 630 | else |
| 631 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 632 | spin_unlock(&tbl->slot_tbl_lock); |
| 633 | return -EAGAIN; |
| 634 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 635 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 636 | |
| 637 | static int nfs40_sequence_done(struct rpc_task *task, |
| 638 | struct nfs4_sequence_res *res) |
| 639 | { |
| 640 | struct nfs4_slot *slot = res->sr_slot; |
| 641 | struct nfs4_slot_table *tbl; |
| 642 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 643 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 644 | goto out; |
| 645 | |
| 646 | tbl = slot->table; |
| 647 | spin_lock(&tbl->slot_tbl_lock); |
| 648 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 649 | nfs4_free_slot(tbl, slot); |
| 650 | spin_unlock(&tbl->slot_tbl_lock); |
| 651 | |
| 652 | res->sr_slot = NULL; |
| 653 | out: |
| 654 | return 1; |
| 655 | } |
| 656 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 657 | #if defined(CONFIG_NFS_V4_1) |
| 658 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 659 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 660 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 661 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 662 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 663 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 664 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 665 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 666 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 667 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 668 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame^] | 669 | /* Bump the slot sequence number */ |
| 670 | if (slot->seq_done) |
| 671 | slot->seq_nr++; |
| 672 | slot->seq_done = 0; |
| 673 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 674 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 675 | /* Be nice to the server: try to ensure that the last transmitted |
| 676 | * value for highest_user_slotid <= target_highest_slotid |
| 677 | */ |
| 678 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 679 | send_new_highest_used_slotid = true; |
| 680 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 681 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 682 | send_new_highest_used_slotid = false; |
| 683 | goto out_unlock; |
| 684 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 685 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 686 | |
| 687 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 688 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 689 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 690 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 691 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 692 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 693 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 694 | if (waitqueue_active(&tbl->slot_waitq)) |
| 695 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 698 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 699 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 700 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 701 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 702 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 703 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 704 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 705 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 706 | if (slot == NULL) |
| 707 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 708 | /* don't increment the sequence number if the task wasn't sent */ |
| 709 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 710 | goto out; |
| 711 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 712 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 713 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 714 | if (slot->interrupted) { |
| 715 | slot->interrupted = 0; |
| 716 | interrupted = true; |
| 717 | } |
| 718 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 719 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 720 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 721 | switch (res->sr_status) { |
| 722 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 723 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame^] | 724 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 725 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 726 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 727 | /* Check sequence flags */ |
Trond Myklebust | b15c7cd | 2015-07-05 15:01:36 -0400 | [diff] [blame] | 728 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 729 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 730 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 731 | case 1: |
| 732 | /* |
| 733 | * sr_status remains 1 if an RPC level error occurred. |
| 734 | * The server may or may not have processed the sequence |
| 735 | * operation.. |
| 736 | * Mark the slot as having hosted an interrupted RPC call. |
| 737 | */ |
| 738 | slot->interrupted = 1; |
| 739 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 740 | case -NFS4ERR_DELAY: |
| 741 | /* The server detected a resend of the RPC call and |
| 742 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 743 | * of RFC5661. |
| 744 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 745 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 746 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 747 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 748 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 749 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 750 | case -NFS4ERR_BADSLOT: |
| 751 | /* |
| 752 | * The slot id we used was probably retired. Try again |
| 753 | * using a different slot id. |
| 754 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 755 | goto retry_nowait; |
| 756 | case -NFS4ERR_SEQ_MISORDERED: |
| 757 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 758 | * Was the last operation on this sequence interrupted? |
| 759 | * If so, retry after bumping the sequence number. |
| 760 | */ |
| 761 | if (interrupted) { |
| 762 | ++slot->seq_nr; |
| 763 | goto retry_nowait; |
| 764 | } |
| 765 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 766 | * Could this slot have been previously retired? |
| 767 | * If so, then the server may be expecting seq_nr = 1! |
| 768 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 769 | if (slot->seq_nr != 1) { |
| 770 | slot->seq_nr = 1; |
| 771 | goto retry_nowait; |
| 772 | } |
| 773 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 774 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 775 | ++slot->seq_nr; |
| 776 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | default: |
| 778 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame^] | 779 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 780 | } |
| 781 | out: |
| 782 | /* The session may be reset by one of the error handlers. */ |
| 783 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 784 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 785 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 786 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 787 | retry_nowait: |
| 788 | if (rpc_restart_call_prepare(task)) { |
| 789 | task->tk_status = 0; |
| 790 | ret = 0; |
| 791 | } |
| 792 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 793 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 794 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 795 | goto out; |
| 796 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 797 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 798 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 799 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 800 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 801 | 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] | 802 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 803 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 804 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 805 | if (!res->sr_slot->table->session) |
| 806 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 807 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 808 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 809 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 810 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 811 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 812 | struct nfs4_sequence_args *args, |
| 813 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 814 | struct rpc_task *task) |
| 815 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 816 | struct nfs4_slot *slot; |
| 817 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 818 | |
| 819 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 820 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 821 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 822 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 823 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 824 | tbl = &session->fc_slot_table; |
| 825 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 826 | task->tk_timeout = 0; |
| 827 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 828 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 829 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 830 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 831 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 832 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 833 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 834 | } |
| 835 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 836 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 837 | if (IS_ERR(slot)) { |
| 838 | /* If out of memory, try again in 1/4 second */ |
| 839 | if (slot == ERR_PTR(-ENOMEM)) |
| 840 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 841 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 842 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 843 | } |
| 844 | spin_unlock(&tbl->slot_tbl_lock); |
| 845 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 846 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 847 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 848 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 849 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 850 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 851 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 852 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 853 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 854 | /* |
| 855 | * sr_status is only set in decode_sequence, and so will remain |
| 856 | * set to 1 if an rpc level failure occurs. |
| 857 | */ |
| 858 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 859 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 860 | out_success: |
| 861 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 862 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 863 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 864 | /* Privileged tasks are queued with top priority */ |
| 865 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 866 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 867 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 868 | else |
| 869 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 870 | spin_unlock(&tbl->slot_tbl_lock); |
| 871 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 872 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 873 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 874 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 875 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 876 | struct nfs4_sequence_args *args, |
| 877 | struct nfs4_sequence_res *res, |
| 878 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 879 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 880 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 881 | int ret = 0; |
| 882 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 883 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 884 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 885 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 886 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 887 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 888 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 889 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 890 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 891 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 892 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 893 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 894 | return ret; |
| 895 | } |
| 896 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 898 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 899 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 900 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 901 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 902 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 903 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 904 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 907 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 908 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 909 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 910 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 911 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 912 | } |
| 913 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 914 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 915 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 916 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 917 | }; |
| 918 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 919 | #else /* !CONFIG_NFS_V4_1 */ |
| 920 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 921 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 922 | struct nfs4_sequence_args *args, |
| 923 | struct nfs4_sequence_res *res, |
| 924 | struct rpc_task *task) |
| 925 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 926 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 927 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 928 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 929 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 930 | int nfs4_sequence_done(struct rpc_task *task, |
| 931 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 932 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 933 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 934 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 935 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 936 | |
| 937 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 938 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 939 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 940 | { |
| 941 | struct nfs4_call_sync_data *data = calldata; |
| 942 | nfs4_setup_sequence(data->seq_server, |
| 943 | data->seq_args, data->seq_res, task); |
| 944 | } |
| 945 | |
| 946 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 947 | { |
| 948 | struct nfs4_call_sync_data *data = calldata; |
| 949 | nfs4_sequence_done(task, data->seq_res); |
| 950 | } |
| 951 | |
| 952 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 953 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 954 | .rpc_call_done = nfs40_call_sync_done, |
| 955 | }; |
| 956 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 957 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 958 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 960 | struct nfs4_sequence_args *args, |
| 961 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 962 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 963 | int ret; |
| 964 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 965 | struct nfs_client *clp = server->nfs_client; |
| 966 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 967 | .seq_server = server, |
| 968 | .seq_args = args, |
| 969 | .seq_res = res, |
| 970 | }; |
| 971 | struct rpc_task_setup task_setup = { |
| 972 | .rpc_client = clnt, |
| 973 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 974 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 975 | .callback_data = &data |
| 976 | }; |
| 977 | |
| 978 | task = rpc_run_task(&task_setup); |
| 979 | if (IS_ERR(task)) |
| 980 | ret = PTR_ERR(task); |
| 981 | else { |
| 982 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 983 | rpc_put_task(task); |
| 984 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 985 | return ret; |
| 986 | } |
| 987 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 988 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 989 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 990 | struct rpc_message *msg, |
| 991 | struct nfs4_sequence_args *args, |
| 992 | struct nfs4_sequence_res *res, |
| 993 | int cache_reply) |
| 994 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 995 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 996 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1000 | { |
| 1001 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1002 | |
| 1003 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1004 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1005 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1007 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1008 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1009 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | spin_unlock(&dir->i_lock); |
| 1011 | } |
| 1012 | |
| 1013 | struct nfs4_opendata { |
| 1014 | struct kref kref; |
| 1015 | struct nfs_openargs o_arg; |
| 1016 | struct nfs_openres o_res; |
| 1017 | struct nfs_open_confirmargs c_arg; |
| 1018 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1019 | struct nfs4_string owner_name; |
| 1020 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1021 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1023 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1025 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | struct nfs4_state_owner *owner; |
| 1027 | struct nfs4_state *state; |
| 1028 | struct iattr attrs; |
| 1029 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1030 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1031 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1032 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1033 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | int cancelled; |
| 1035 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1036 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1037 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1038 | int err, struct nfs4_exception *exception) |
| 1039 | { |
| 1040 | if (err != -EINVAL) |
| 1041 | return false; |
| 1042 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1043 | return false; |
| 1044 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1045 | exception->retry = 1; |
| 1046 | return true; |
| 1047 | } |
| 1048 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1049 | static u32 |
| 1050 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1051 | fmode_t fmode, int openflags) |
| 1052 | { |
| 1053 | u32 res = 0; |
| 1054 | |
| 1055 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1056 | case FMODE_READ: |
| 1057 | res = NFS4_SHARE_ACCESS_READ; |
| 1058 | break; |
| 1059 | case FMODE_WRITE: |
| 1060 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1061 | break; |
| 1062 | case FMODE_READ|FMODE_WRITE: |
| 1063 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1064 | } |
| 1065 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1066 | goto out; |
| 1067 | /* Want no delegation if we're using O_DIRECT */ |
| 1068 | if (openflags & O_DIRECT) |
| 1069 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1070 | out: |
| 1071 | return res; |
| 1072 | } |
| 1073 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1074 | static enum open_claim_type4 |
| 1075 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1076 | enum open_claim_type4 claim) |
| 1077 | { |
| 1078 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1079 | return claim; |
| 1080 | switch (claim) { |
| 1081 | default: |
| 1082 | return claim; |
| 1083 | case NFS4_OPEN_CLAIM_FH: |
| 1084 | return NFS4_OPEN_CLAIM_NULL; |
| 1085 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1086 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1087 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1088 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1089 | } |
| 1090 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1093 | { |
| 1094 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1095 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1096 | p->o_res.seqid = p->o_arg.seqid; |
| 1097 | p->c_res.seqid = p->c_arg.seqid; |
| 1098 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1099 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1100 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1101 | 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] | 1102 | } |
| 1103 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1104 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1105 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1106 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1107 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1108 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1109 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1111 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1112 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1113 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1114 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1115 | struct nfs4_opendata *p; |
| 1116 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1117 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1118 | if (p == NULL) |
| 1119 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1120 | |
| 1121 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1122 | if (IS_ERR(p->f_label)) |
| 1123 | goto err_free_p; |
| 1124 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1125 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1126 | if (IS_ERR(p->a_label)) |
| 1127 | goto err_free_f; |
| 1128 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1129 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1130 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1131 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1132 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1133 | nfs_sb_active(dentry->d_sb); |
| 1134 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1135 | p->dir = parent; |
| 1136 | p->owner = sp; |
| 1137 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1138 | p->o_arg.open_flags = flags; |
| 1139 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1140 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1141 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1142 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1143 | * will return permission denied for all bits until close */ |
| 1144 | if (!(flags & O_EXCL)) { |
| 1145 | /* ask server to check for all possible rights as results |
| 1146 | * are cached */ |
| 1147 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1148 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1149 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1150 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1151 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1152 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1153 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1154 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1155 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1156 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1157 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1158 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1159 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1160 | case NFS4_OPEN_CLAIM_NULL: |
| 1161 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1162 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1163 | p->o_arg.fh = NFS_FH(dir); |
| 1164 | break; |
| 1165 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1166 | case NFS4_OPEN_CLAIM_FH: |
| 1167 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1168 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1169 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1170 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1171 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1172 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1173 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1174 | p->o_arg.u.attrs = &p->attrs; |
| 1175 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1176 | |
| 1177 | verf[0] = jiffies; |
| 1178 | verf[1] = current->pid; |
| 1179 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1180 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1181 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1182 | p->c_arg.fh = &p->o_res.fh; |
| 1183 | p->c_arg.stateid = &p->o_res.stateid; |
| 1184 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1185 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1186 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1188 | |
| 1189 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1190 | nfs4_label_free(p->a_label); |
| 1191 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1192 | nfs4_label_free(p->f_label); |
| 1193 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1194 | kfree(p); |
| 1195 | err: |
| 1196 | dput(parent); |
| 1197 | return NULL; |
| 1198 | } |
| 1199 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1200 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1201 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1202 | struct nfs4_opendata *p = container_of(kref, |
| 1203 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1204 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1205 | |
| 1206 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1207 | if (p->state != NULL) |
| 1208 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1209 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1210 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1211 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1212 | nfs4_label_free(p->f_label); |
| 1213 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1214 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1215 | dput(p->dentry); |
| 1216 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1217 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1218 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1219 | kfree(p); |
| 1220 | } |
| 1221 | |
| 1222 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1223 | { |
| 1224 | if (p != NULL) |
| 1225 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1226 | } |
| 1227 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1228 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1229 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1230 | int ret; |
| 1231 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1232 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1233 | return ret; |
| 1234 | } |
| 1235 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1236 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1237 | fmode_t fmode) |
| 1238 | { |
| 1239 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1240 | case FMODE_READ|FMODE_WRITE: |
| 1241 | return state->n_rdwr != 0; |
| 1242 | case FMODE_WRITE: |
| 1243 | return state->n_wronly != 0; |
| 1244 | case FMODE_READ: |
| 1245 | return state->n_rdonly != 0; |
| 1246 | } |
| 1247 | WARN_ON_ONCE(1); |
| 1248 | return false; |
| 1249 | } |
| 1250 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1251 | 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] | 1252 | { |
| 1253 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1254 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1255 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1256 | goto out; |
| 1257 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1258 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1259 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1260 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1261 | break; |
| 1262 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1263 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1264 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1265 | break; |
| 1266 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1267 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1268 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1269 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1270 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1271 | return ret; |
| 1272 | } |
| 1273 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1274 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1275 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1276 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1277 | if (delegation == NULL) |
| 1278 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1279 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1280 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1281 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1282 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1283 | switch (claim) { |
| 1284 | case NFS4_OPEN_CLAIM_NULL: |
| 1285 | case NFS4_OPEN_CLAIM_FH: |
| 1286 | break; |
| 1287 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1288 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1289 | break; |
| 1290 | default: |
| 1291 | return 0; |
| 1292 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1293 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1294 | return 1; |
| 1295 | } |
| 1296 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1297 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1298 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1299 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1300 | case FMODE_WRITE: |
| 1301 | state->n_wronly++; |
| 1302 | break; |
| 1303 | case FMODE_READ: |
| 1304 | state->n_rdonly++; |
| 1305 | break; |
| 1306 | case FMODE_READ|FMODE_WRITE: |
| 1307 | state->n_rdwr++; |
| 1308 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1312 | 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] | 1313 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1314 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1315 | bool need_recover = false; |
| 1316 | |
| 1317 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1318 | need_recover = true; |
| 1319 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1320 | need_recover = true; |
| 1321 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1322 | need_recover = true; |
| 1323 | if (need_recover) |
| 1324 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1325 | } |
| 1326 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1327 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1328 | nfs4_stateid *stateid) |
| 1329 | { |
| 1330 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1331 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1332 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1333 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1334 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1335 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1336 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1337 | return true; |
| 1338 | return false; |
| 1339 | } |
| 1340 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1341 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1342 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1343 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1344 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1345 | if (state->n_wronly) |
| 1346 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1347 | if (state->n_rdonly) |
| 1348 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1349 | if (state->n_rdwr) |
| 1350 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1351 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1352 | } |
| 1353 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1354 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1355 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1356 | nfs4_stateid *stateid, fmode_t fmode) |
| 1357 | { |
| 1358 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1359 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1360 | case FMODE_WRITE: |
| 1361 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1362 | break; |
| 1363 | case FMODE_READ: |
| 1364 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1365 | break; |
| 1366 | case 0: |
| 1367 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1368 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1369 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1370 | } |
| 1371 | if (stateid == NULL) |
| 1372 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1373 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1374 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1375 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1376 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1377 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1378 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1379 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1380 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1381 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1382 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1383 | } |
| 1384 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1385 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1386 | nfs4_stateid *arg_stateid, |
| 1387 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1388 | { |
| 1389 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1390 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1391 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1392 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1393 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1394 | } |
| 1395 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1396 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1397 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1398 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1399 | case FMODE_READ: |
| 1400 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1401 | break; |
| 1402 | case FMODE_WRITE: |
| 1403 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1404 | break; |
| 1405 | case FMODE_READ|FMODE_WRITE: |
| 1406 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1407 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1408 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1409 | return; |
| 1410 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1411 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1412 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1415 | 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] | 1416 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1417 | /* |
| 1418 | * Protect the call to nfs4_state_set_mode_locked and |
| 1419 | * serialise the stateid update |
| 1420 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1421 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1422 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1423 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1424 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1425 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1426 | } |
| 1427 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1428 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1429 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1430 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1431 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1434 | 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] | 1435 | { |
| 1436 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1437 | struct nfs_delegation *deleg_cur; |
| 1438 | int ret = 0; |
| 1439 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1440 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1441 | |
| 1442 | rcu_read_lock(); |
| 1443 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1444 | if (deleg_cur == NULL) |
| 1445 | goto no_delegation; |
| 1446 | |
| 1447 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1448 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1449 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1450 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1451 | goto no_delegation_unlock; |
| 1452 | |
| 1453 | if (delegation == NULL) |
| 1454 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1455 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1456 | goto no_delegation_unlock; |
| 1457 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1458 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1459 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1460 | ret = 1; |
| 1461 | no_delegation_unlock: |
| 1462 | spin_unlock(&deleg_cur->lock); |
| 1463 | no_delegation: |
| 1464 | rcu_read_unlock(); |
| 1465 | |
| 1466 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1467 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1468 | ret = 1; |
| 1469 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1470 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1471 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1472 | |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1476 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1477 | const nfs4_stateid *stateid) |
| 1478 | { |
| 1479 | struct nfs4_state *state = lsp->ls_state; |
| 1480 | bool ret = false; |
| 1481 | |
| 1482 | spin_lock(&state->state_lock); |
| 1483 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1484 | goto out_noupdate; |
| 1485 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1486 | goto out_noupdate; |
| 1487 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1488 | ret = true; |
| 1489 | out_noupdate: |
| 1490 | spin_unlock(&state->state_lock); |
| 1491 | return ret; |
| 1492 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1493 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1494 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1495 | { |
| 1496 | struct nfs_delegation *delegation; |
| 1497 | |
| 1498 | rcu_read_lock(); |
| 1499 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1501 | rcu_read_unlock(); |
| 1502 | return; |
| 1503 | } |
| 1504 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1505 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1508 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1509 | { |
| 1510 | struct nfs4_state *state = opendata->state; |
| 1511 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1512 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1513 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1514 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1515 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1516 | nfs4_stateid stateid; |
| 1517 | int ret = -EAGAIN; |
| 1518 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1519 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1520 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1521 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1522 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1523 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1524 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1525 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1526 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1527 | rcu_read_lock(); |
| 1528 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1529 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1530 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1531 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1532 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1533 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1534 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1535 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1536 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1537 | if (!opendata->is_recover) { |
| 1538 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1539 | if (ret != 0) |
| 1540 | goto out; |
| 1541 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1542 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1543 | |
| 1544 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1545 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1546 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1547 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | out: |
| 1549 | return ERR_PTR(ret); |
| 1550 | out_return_state: |
| 1551 | atomic_inc(&state->count); |
| 1552 | return state; |
| 1553 | } |
| 1554 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1555 | static void |
| 1556 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1557 | { |
| 1558 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1559 | struct nfs_delegation *delegation; |
| 1560 | int delegation_flags = 0; |
| 1561 | |
| 1562 | rcu_read_lock(); |
| 1563 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1564 | if (delegation) |
| 1565 | delegation_flags = delegation->flags; |
| 1566 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1567 | switch (data->o_arg.claim) { |
| 1568 | default: |
| 1569 | break; |
| 1570 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1571 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1572 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1573 | "returning a delegation for " |
| 1574 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1575 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1576 | return; |
| 1577 | } |
| 1578 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1579 | nfs_inode_set_delegation(state->inode, |
| 1580 | data->owner->so_cred, |
| 1581 | &data->o_res); |
| 1582 | else |
| 1583 | nfs_inode_reclaim_delegation(state->inode, |
| 1584 | data->owner->so_cred, |
| 1585 | &data->o_res); |
| 1586 | } |
| 1587 | |
| 1588 | /* |
| 1589 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1590 | * and update the nfs4_state. |
| 1591 | */ |
| 1592 | static struct nfs4_state * |
| 1593 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1594 | { |
| 1595 | struct inode *inode = data->state->inode; |
| 1596 | struct nfs4_state *state = data->state; |
| 1597 | int ret; |
| 1598 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1599 | if (!data->rpc_done) { |
| 1600 | if (data->rpc_status) { |
| 1601 | ret = data->rpc_status; |
| 1602 | goto err; |
| 1603 | } |
| 1604 | /* cached opens have already been processed */ |
| 1605 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1606 | } |
| 1607 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1608 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1609 | if (ret) |
| 1610 | goto err; |
| 1611 | |
| 1612 | if (data->o_res.delegation_type != 0) |
| 1613 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1614 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1615 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1616 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1617 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1618 | |
| 1619 | return state; |
| 1620 | err: |
| 1621 | return ERR_PTR(ret); |
| 1622 | |
| 1623 | } |
| 1624 | |
| 1625 | static struct nfs4_state * |
| 1626 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1627 | { |
| 1628 | struct inode *inode; |
| 1629 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1630 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1631 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1632 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1633 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1634 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1635 | goto out; |
| 1636 | } |
| 1637 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1638 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1639 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1640 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1641 | 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] | 1642 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1643 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1644 | goto err; |
| 1645 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1646 | state = nfs4_get_open_state(inode, data->owner); |
| 1647 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1648 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1649 | if (data->o_res.delegation_type != 0) |
| 1650 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1651 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1652 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1653 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1654 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1655 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1656 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1657 | err_put_inode: |
| 1658 | iput(inode); |
| 1659 | err: |
| 1660 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1663 | static struct nfs4_state * |
| 1664 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1665 | { |
| 1666 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1667 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1668 | return _nfs4_opendata_to_nfs4_state(data); |
| 1669 | } |
| 1670 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1671 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1672 | { |
| 1673 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1674 | struct nfs_open_context *ctx; |
| 1675 | |
| 1676 | spin_lock(&state->inode->i_lock); |
| 1677 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1678 | if (ctx->state != state) |
| 1679 | continue; |
| 1680 | get_nfs_open_context(ctx); |
| 1681 | spin_unlock(&state->inode->i_lock); |
| 1682 | return ctx; |
| 1683 | } |
| 1684 | spin_unlock(&state->inode->i_lock); |
| 1685 | return ERR_PTR(-ENOENT); |
| 1686 | } |
| 1687 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1688 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1689 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1690 | { |
| 1691 | struct nfs4_opendata *opendata; |
| 1692 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1693 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1694 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1695 | if (opendata == NULL) |
| 1696 | return ERR_PTR(-ENOMEM); |
| 1697 | opendata->state = state; |
| 1698 | atomic_inc(&state->count); |
| 1699 | return opendata; |
| 1700 | } |
| 1701 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1702 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1703 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1704 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1705 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1706 | int ret; |
| 1707 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1708 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1709 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1710 | opendata->o_arg.open_flags = 0; |
| 1711 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1712 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1713 | NFS_SB(opendata->dentry->d_sb), |
| 1714 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1715 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1716 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1717 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1718 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1719 | if (ret != 0) |
| 1720 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1721 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1722 | if (IS_ERR(newstate)) |
| 1723 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1724 | if (newstate != opendata->state) |
| 1725 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1726 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1727 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1731 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1732 | int ret; |
| 1733 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1734 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1735 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1736 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1737 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1738 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1739 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1740 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1741 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1742 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1743 | if (ret != 0) |
| 1744 | return ret; |
| 1745 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1746 | if (ret != 0) |
| 1747 | return ret; |
| 1748 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1749 | if (ret != 0) |
| 1750 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1751 | /* |
| 1752 | * We may have performed cached opens for all three recoveries. |
| 1753 | * Check if we need to update the current stateid. |
| 1754 | */ |
| 1755 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1756 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1757 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1758 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1759 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1760 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1761 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1762 | return 0; |
| 1763 | } |
| 1764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | /* |
| 1766 | * OPEN_RECLAIM: |
| 1767 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1769 | 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] | 1770 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1771 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1772 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1773 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | int status; |
| 1775 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1776 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1777 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1778 | if (IS_ERR(opendata)) |
| 1779 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1780 | rcu_read_lock(); |
| 1781 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1782 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1783 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1784 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1785 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1786 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1787 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | return status; |
| 1789 | } |
| 1790 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1791 | 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] | 1792 | { |
| 1793 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1794 | struct nfs4_exception exception = { }; |
| 1795 | int err; |
| 1796 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1797 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1798 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1799 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1800 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1801 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1802 | break; |
| 1803 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } while (exception.retry); |
| 1805 | return err; |
| 1806 | } |
| 1807 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1808 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1809 | { |
| 1810 | struct nfs_open_context *ctx; |
| 1811 | int ret; |
| 1812 | |
| 1813 | ctx = nfs4_state_find_open_context(state); |
| 1814 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1815 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1816 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1817 | put_nfs_open_context(ctx); |
| 1818 | return ret; |
| 1819 | } |
| 1820 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1821 | 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] | 1822 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1823 | switch (err) { |
| 1824 | default: |
| 1825 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1826 | "%d.\n", __func__, err); |
| 1827 | case 0: |
| 1828 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1829 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1830 | case -ESTALE: |
| 1831 | break; |
| 1832 | case -NFS4ERR_BADSESSION: |
| 1833 | case -NFS4ERR_BADSLOT: |
| 1834 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1835 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1836 | case -NFS4ERR_DEADSESSION: |
| 1837 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1838 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1839 | return -EAGAIN; |
| 1840 | case -NFS4ERR_STALE_CLIENTID: |
| 1841 | case -NFS4ERR_STALE_STATEID: |
| 1842 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1843 | case -NFS4ERR_EXPIRED: |
| 1844 | /* Don't recall a delegation if it was lost */ |
| 1845 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1846 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1847 | case -NFS4ERR_MOVED: |
| 1848 | nfs4_schedule_migration_recovery(server); |
| 1849 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1850 | case -NFS4ERR_LEASE_MOVED: |
| 1851 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1852 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1853 | case -NFS4ERR_DELEG_REVOKED: |
| 1854 | case -NFS4ERR_ADMIN_REVOKED: |
| 1855 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1856 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1857 | nfs_inode_find_state_and_recover(state->inode, |
| 1858 | stateid); |
| 1859 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1860 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1861 | case -NFS4ERR_DELAY: |
| 1862 | case -NFS4ERR_GRACE: |
| 1863 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1864 | ssleep(1); |
| 1865 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1866 | case -ENOMEM: |
| 1867 | case -NFS4ERR_DENIED: |
| 1868 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1869 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1870 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | return err; |
| 1872 | } |
| 1873 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1874 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1875 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1876 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1877 | { |
| 1878 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1879 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1880 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1881 | |
| 1882 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1883 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1884 | if (IS_ERR(opendata)) |
| 1885 | return PTR_ERR(opendata); |
| 1886 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1887 | write_seqlock(&state->seqlock); |
| 1888 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1889 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1890 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1891 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1892 | case FMODE_READ|FMODE_WRITE: |
| 1893 | case FMODE_WRITE: |
| 1894 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1895 | if (err) |
| 1896 | break; |
| 1897 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1898 | if (err) |
| 1899 | break; |
| 1900 | case FMODE_READ: |
| 1901 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1902 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1903 | nfs4_opendata_put(opendata); |
| 1904 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1905 | } |
| 1906 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1907 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1908 | { |
| 1909 | struct nfs4_opendata *data = calldata; |
| 1910 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1911 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1912 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1913 | } |
| 1914 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1915 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1916 | { |
| 1917 | struct nfs4_opendata *data = calldata; |
| 1918 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1919 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1920 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1921 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1922 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1923 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1924 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1925 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1926 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1927 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | static void nfs4_open_confirm_release(void *calldata) |
| 1931 | { |
| 1932 | struct nfs4_opendata *data = calldata; |
| 1933 | struct nfs4_state *state = NULL; |
| 1934 | |
| 1935 | /* If this request hasn't been cancelled, do nothing */ |
| 1936 | if (data->cancelled == 0) |
| 1937 | goto out_free; |
| 1938 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1939 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1940 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1941 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1942 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1943 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1944 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1945 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1949 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1950 | .rpc_call_done = nfs4_open_confirm_done, |
| 1951 | .rpc_release = nfs4_open_confirm_release, |
| 1952 | }; |
| 1953 | |
| 1954 | /* |
| 1955 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1956 | */ |
| 1957 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1958 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1959 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1960 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1961 | struct rpc_message msg = { |
| 1962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1963 | .rpc_argp = &data->c_arg, |
| 1964 | .rpc_resp = &data->c_res, |
| 1965 | .rpc_cred = data->owner->so_cred, |
| 1966 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1967 | struct rpc_task_setup task_setup_data = { |
| 1968 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1969 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1970 | .callback_ops = &nfs4_open_confirm_ops, |
| 1971 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1972 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1973 | .flags = RPC_TASK_ASYNC, |
| 1974 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | int status; |
| 1976 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1977 | 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] | 1978 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1979 | data->rpc_done = 0; |
| 1980 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1981 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 1982 | if (data->is_recover) |
| 1983 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1984 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1985 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1986 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1987 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1988 | if (status != 0) { |
| 1989 | data->cancelled = 1; |
| 1990 | smp_wmb(); |
| 1991 | } else |
| 1992 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1993 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | return status; |
| 1995 | } |
| 1996 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1997 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1999 | struct nfs4_opendata *data = calldata; |
| 2000 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2001 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2002 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2003 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2004 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2005 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2006 | /* |
| 2007 | * Check if we still need to send an OPEN call, or if we can use |
| 2008 | * a delegation instead. |
| 2009 | */ |
| 2010 | if (data->state != NULL) { |
| 2011 | struct nfs_delegation *delegation; |
| 2012 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2013 | 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] | 2014 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2015 | rcu_read_lock(); |
| 2016 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2017 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2018 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2019 | rcu_read_unlock(); |
| 2020 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2021 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2022 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2023 | switch (claim) { |
| 2024 | default: |
| 2025 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2026 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2027 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2028 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2029 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2030 | case NFS4_OPEN_CLAIM_FH: |
| 2031 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2032 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2033 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2034 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2035 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2036 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2037 | &data->o_res.seq_res, |
| 2038 | task) != 0) |
| 2039 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2040 | |
| 2041 | /* Set the create mode (note dependency on the session type) */ |
| 2042 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2043 | if (data->o_arg.open_flags & O_EXCL) { |
| 2044 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2045 | if (nfs4_has_persistent_session(clp)) |
| 2046 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2047 | else if (clp->cl_mvops->minor_version > 0) |
| 2048 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2049 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2050 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2051 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2052 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2053 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2054 | out_no_action: |
| 2055 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2056 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2057 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2060 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2061 | { |
| 2062 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2064 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2065 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2066 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 2067 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2068 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2069 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2070 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2071 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2072 | case S_IFREG: |
| 2073 | break; |
| 2074 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2075 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2076 | break; |
| 2077 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2078 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2079 | break; |
| 2080 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2081 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2082 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2083 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2084 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2085 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2086 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2087 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2088 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2089 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2090 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2091 | static void nfs4_open_release(void *calldata) |
| 2092 | { |
| 2093 | struct nfs4_opendata *data = calldata; |
| 2094 | struct nfs4_state *state = NULL; |
| 2095 | |
| 2096 | /* If this request hasn't been cancelled, do nothing */ |
| 2097 | if (data->cancelled == 0) |
| 2098 | goto out_free; |
| 2099 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2100 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2101 | goto out_free; |
| 2102 | /* In case we need an open_confirm, no cleanup! */ |
| 2103 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2104 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2105 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2106 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2107 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2108 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2109 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2113 | .rpc_call_prepare = nfs4_open_prepare, |
| 2114 | .rpc_call_done = nfs4_open_done, |
| 2115 | .rpc_release = nfs4_open_release, |
| 2116 | }; |
| 2117 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2118 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2119 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2120 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2121 | struct nfs_server *server = NFS_SERVER(dir); |
| 2122 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2123 | struct nfs_openres *o_res = &data->o_res; |
| 2124 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2125 | struct rpc_message msg = { |
| 2126 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2127 | .rpc_argp = o_arg, |
| 2128 | .rpc_resp = o_res, |
| 2129 | .rpc_cred = data->owner->so_cred, |
| 2130 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2131 | struct rpc_task_setup task_setup_data = { |
| 2132 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2133 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2134 | .callback_ops = &nfs4_open_ops, |
| 2135 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2136 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2137 | .flags = RPC_TASK_ASYNC, |
| 2138 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2139 | int status; |
| 2140 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2141 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2142 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2143 | data->rpc_done = 0; |
| 2144 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2145 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2146 | data->is_recover = 0; |
| 2147 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2148 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2149 | data->is_recover = 1; |
| 2150 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2151 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2152 | if (IS_ERR(task)) |
| 2153 | return PTR_ERR(task); |
| 2154 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2155 | if (status != 0) { |
| 2156 | data->cancelled = 1; |
| 2157 | smp_wmb(); |
| 2158 | } else |
| 2159 | status = data->rpc_status; |
| 2160 | rpc_put_task(task); |
| 2161 | |
| 2162 | return status; |
| 2163 | } |
| 2164 | |
| 2165 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2166 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2167 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2168 | struct nfs_openres *o_res = &data->o_res; |
| 2169 | int status; |
| 2170 | |
| 2171 | status = nfs4_run_open_task(data, 1); |
| 2172 | if (status != 0 || !data->rpc_done) |
| 2173 | return status; |
| 2174 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2175 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2176 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2177 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2178 | status = _nfs4_proc_open_confirm(data); |
| 2179 | if (status != 0) |
| 2180 | return status; |
| 2181 | } |
| 2182 | |
| 2183 | return status; |
| 2184 | } |
| 2185 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2186 | /* |
| 2187 | * Additional permission checks in order to distinguish between an |
| 2188 | * open for read, and an open for execute. This works around the |
| 2189 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2190 | * the same. |
| 2191 | * Note that in the non-execute case, we want to turn off permission |
| 2192 | * checking if we just created a new file (POSIX open() semantics). |
| 2193 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2194 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2195 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2196 | struct nfs4_state *state, fmode_t fmode, |
| 2197 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2198 | { |
| 2199 | struct nfs_access_entry cache; |
| 2200 | u32 mask; |
| 2201 | |
| 2202 | /* access call failed or for some reason the server doesn't |
| 2203 | * support any access modes -- defer access call until later */ |
| 2204 | if (opendata->o_res.access_supported == 0) |
| 2205 | return 0; |
| 2206 | |
| 2207 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2208 | /* |
| 2209 | * Use openflags to check for exec, because fmode won't |
| 2210 | * always have FMODE_EXEC set when file open for exec. |
| 2211 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2212 | if (openflags & __FMODE_EXEC) { |
| 2213 | /* ONLY check for exec rights */ |
| 2214 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2215 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2216 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2217 | |
| 2218 | cache.cred = cred; |
| 2219 | cache.jiffies = jiffies; |
| 2220 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2221 | nfs_access_add_cache(state->inode, &cache); |
| 2222 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2223 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2224 | return 0; |
| 2225 | |
| 2226 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2227 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2228 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2229 | } |
| 2230 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2231 | /* |
| 2232 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2233 | */ |
| 2234 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2235 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2236 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2237 | struct nfs_server *server = NFS_SERVER(dir); |
| 2238 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2239 | struct nfs_openres *o_res = &data->o_res; |
| 2240 | int status; |
| 2241 | |
| 2242 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2243 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2244 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2245 | if (status != 0) { |
| 2246 | if (status == -NFS4ERR_BADNAME && |
| 2247 | !(o_arg->open_flags & O_CREAT)) |
| 2248 | return -ENOENT; |
| 2249 | return status; |
| 2250 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2251 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2252 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2253 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2254 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2255 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2256 | if (o_arg->open_flags & O_EXCL) |
| 2257 | data->file_created = 1; |
| 2258 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2259 | data->file_created = 1; |
| 2260 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2261 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2262 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2264 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2266 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | } |
| 2268 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2269 | 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] | 2270 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2273 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2274 | { |
| 2275 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2276 | } |
| 2277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | /* |
| 2279 | * OPEN_EXPIRED: |
| 2280 | * reclaim state on the server after a network partition. |
| 2281 | * Assumes caller holds the appropriate lock |
| 2282 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2283 | 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] | 2284 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2285 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2286 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2288 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2289 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2290 | if (IS_ERR(opendata)) |
| 2291 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2292 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2293 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2294 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2295 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2296 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2299 | 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] | 2300 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2301 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2302 | struct nfs4_exception exception = { }; |
| 2303 | int err; |
| 2304 | |
| 2305 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2306 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2307 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2308 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2309 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2310 | switch (err) { |
| 2311 | default: |
| 2312 | goto out; |
| 2313 | case -NFS4ERR_GRACE: |
| 2314 | case -NFS4ERR_DELAY: |
| 2315 | nfs4_handle_exception(server, err, &exception); |
| 2316 | err = 0; |
| 2317 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2318 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2319 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2320 | return err; |
| 2321 | } |
| 2322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2324 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2326 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2328 | ctx = nfs4_state_find_open_context(state); |
| 2329 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2330 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2331 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2332 | put_nfs_open_context(ctx); |
| 2333 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2336 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2337 | { |
| 2338 | nfs_remove_bad_delegation(state->inode); |
| 2339 | write_seqlock(&state->seqlock); |
| 2340 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2341 | write_sequnlock(&state->seqlock); |
| 2342 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2343 | } |
| 2344 | |
| 2345 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2346 | { |
| 2347 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2348 | nfs_finish_clear_delegation_stateid(state); |
| 2349 | } |
| 2350 | |
| 2351 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2352 | { |
| 2353 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2354 | nfs40_clear_delegation_stateid(state); |
| 2355 | return nfs4_open_expired(sp, state); |
| 2356 | } |
| 2357 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2358 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2359 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2360 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2361 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2362 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2363 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2364 | struct rpc_cred *cred; |
| 2365 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2366 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2367 | /* Get the delegation credential for use by test/free_stateid */ |
| 2368 | rcu_read_lock(); |
| 2369 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2370 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2371 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2372 | return; |
| 2373 | } |
| 2374 | |
| 2375 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2376 | cred = get_rpccred(delegation->cred); |
| 2377 | rcu_read_unlock(); |
| 2378 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2379 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2380 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2381 | if (status != NFS_OK) { |
| 2382 | /* Free the stateid unless the server explicitly |
| 2383 | * informs us the stateid is unrecognized. */ |
| 2384 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2385 | nfs41_free_stateid(server, &stateid, cred); |
| 2386 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2387 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2388 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2389 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2394 | * |
| 2395 | * @state: NFSv4 state for an inode |
| 2396 | * |
| 2397 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2398 | * Otherwise a negative NFS4ERR value is returned. |
| 2399 | */ |
| 2400 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2401 | { |
| 2402 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2403 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2404 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2405 | int status; |
| 2406 | |
| 2407 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2408 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2409 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2410 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2411 | return -NFS4ERR_BAD_STATEID; |
| 2412 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2413 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2414 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2415 | if (status != NFS_OK) { |
| 2416 | /* Free the stateid unless the server explicitly |
| 2417 | * informs us the stateid is unrecognized. */ |
| 2418 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2419 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2420 | |
| 2421 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2422 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2423 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2424 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2425 | } |
| 2426 | return status; |
| 2427 | } |
| 2428 | |
| 2429 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2430 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2431 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2432 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2433 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2434 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2435 | if (status != NFS_OK) |
| 2436 | status = nfs4_open_expired(sp, state); |
| 2437 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2438 | } |
| 2439 | #endif |
| 2440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2442 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2443 | * fields corresponding to attributes that were used to store the verifier. |
| 2444 | * Make sure we clobber those fields in the later setattr call |
| 2445 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2446 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2447 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2448 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2449 | const u32 *attrset = opendata->o_res.attrset; |
| 2450 | |
| 2451 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2452 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2453 | sattr->ia_valid |= ATTR_ATIME; |
| 2454 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2455 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2456 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2457 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2458 | |
| 2459 | /* Except MODE, it seems harmless of setting twice. */ |
| 2460 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2461 | sattr->ia_valid &= ~ATTR_MODE; |
| 2462 | |
| 2463 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2464 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2465 | } |
| 2466 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2467 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2468 | fmode_t fmode, |
| 2469 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2470 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2471 | { |
| 2472 | struct nfs4_state_owner *sp = opendata->owner; |
| 2473 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2474 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2475 | struct nfs4_state *state; |
| 2476 | unsigned int seq; |
| 2477 | int ret; |
| 2478 | |
| 2479 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2480 | |
| 2481 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2482 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2483 | goto out; |
| 2484 | |
| 2485 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2486 | ret = PTR_ERR(state); |
| 2487 | if (IS_ERR(state)) |
| 2488 | goto out; |
| 2489 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2490 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2491 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2492 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2493 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2494 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2495 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2496 | alias = d_exact_alias(dentry, state->inode); |
| 2497 | if (!alias) |
| 2498 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2499 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2500 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2501 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2502 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2503 | } |
| 2504 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2505 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2506 | } |
| 2507 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2508 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2509 | if (ret != 0) |
| 2510 | goto out; |
| 2511 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2512 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2513 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2514 | nfs_inode_attach_open_context(ctx); |
| 2515 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2516 | nfs4_schedule_stateid_recovery(server, state); |
| 2517 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2518 | out: |
| 2519 | return ret; |
| 2520 | } |
| 2521 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2522 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2523 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2525 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2526 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2527 | int flags, |
| 2528 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2529 | struct nfs4_label *label, |
| 2530 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | { |
| 2532 | struct nfs4_state_owner *sp; |
| 2533 | struct nfs4_state *state = NULL; |
| 2534 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2535 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2536 | struct dentry *dentry = ctx->dentry; |
| 2537 | struct rpc_cred *cred = ctx->cred; |
| 2538 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2539 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2540 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2541 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2542 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
| 2544 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2546 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2547 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2549 | goto out_err; |
| 2550 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2551 | status = nfs4_recover_expired_lease(server); |
| 2552 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2553 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2554 | if (d_really_is_positive(dentry)) |
| 2555 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2556 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2557 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2558 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2559 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2560 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2561 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2562 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2564 | if (label) { |
| 2565 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2566 | if (IS_ERR(olabel)) { |
| 2567 | status = PTR_ERR(olabel); |
| 2568 | goto err_opendata_put; |
| 2569 | } |
| 2570 | } |
| 2571 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2572 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2573 | if (!opendata->f_attr.mdsthreshold) { |
| 2574 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2575 | if (!opendata->f_attr.mdsthreshold) |
| 2576 | goto err_free_label; |
| 2577 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2578 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2579 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2580 | if (d_really_is_positive(dentry)) |
| 2581 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2582 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2583 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2584 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2585 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2586 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2587 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2588 | 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] | 2589 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2590 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2591 | /* |
| 2592 | * send create attributes which was not set by open |
| 2593 | * with an extra setattr. |
| 2594 | */ |
| 2595 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2596 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2597 | status = nfs4_do_setattr(state->inode, cred, |
| 2598 | opendata->o_res.f_attr, sattr, |
| 2599 | state, label, olabel); |
| 2600 | if (status == 0) { |
| 2601 | nfs_setattr_update_inode(state->inode, sattr, |
| 2602 | opendata->o_res.f_attr); |
| 2603 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2604 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2605 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2606 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2607 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2608 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2609 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2610 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2611 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2612 | opendata->f_attr.mdsthreshold = NULL; |
| 2613 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2614 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2615 | nfs4_label_free(olabel); |
| 2616 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2617 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2620 | err_free_label: |
| 2621 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2622 | err_opendata_put: |
| 2623 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2624 | err_put_state_owner: |
| 2625 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | return status; |
| 2628 | } |
| 2629 | |
| 2630 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2631 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2632 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2633 | int flags, |
| 2634 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2635 | struct nfs4_label *label, |
| 2636 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2638 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | struct nfs4_exception exception = { }; |
| 2640 | struct nfs4_state *res; |
| 2641 | int status; |
| 2642 | |
| 2643 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2644 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2645 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2646 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | if (status == 0) |
| 2648 | break; |
| 2649 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2650 | * book-keeping w.r.t. state-changing operations |
| 2651 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2652 | * It is actually a sign of a bug on the client or on the server. |
| 2653 | * |
| 2654 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2655 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | * have unhashed the old state_owner for us, and that we can |
| 2657 | * therefore safely retry using a new one. We should still warn |
| 2658 | * the user though... |
| 2659 | */ |
| 2660 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2661 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2662 | " returned a bad sequence-id error!\n", |
| 2663 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | exception.retry = 1; |
| 2665 | continue; |
| 2666 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2667 | /* |
| 2668 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2669 | * state before it received the OPEN_CONFIRM. |
| 2670 | * Recover by retrying the request as per the discussion |
| 2671 | * on Page 181 of RFC3530. |
| 2672 | */ |
| 2673 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2674 | exception.retry = 1; |
| 2675 | continue; |
| 2676 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2677 | if (status == -EAGAIN) { |
| 2678 | /* We must have found a delegation */ |
| 2679 | exception.retry = 1; |
| 2680 | continue; |
| 2681 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2682 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2683 | continue; |
| 2684 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | status, &exception)); |
| 2686 | } while (exception.retry); |
| 2687 | return res; |
| 2688 | } |
| 2689 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2690 | static int _nfs4_do_setattr(struct inode *inode, |
| 2691 | struct nfs_setattrargs *arg, |
| 2692 | struct nfs_setattrres *res, |
| 2693 | struct rpc_cred *cred, |
| 2694 | struct nfs4_state *state) |
| 2695 | { |
| 2696 | struct nfs_server *server = NFS_SERVER(inode); |
| 2697 | struct rpc_message msg = { |
| 2698 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2699 | .rpc_argp = arg, |
| 2700 | .rpc_resp = res, |
| 2701 | .rpc_cred = cred, |
| 2702 | }; |
| 2703 | struct rpc_cred *delegation_cred = NULL; |
| 2704 | unsigned long timestamp = jiffies; |
| 2705 | fmode_t fmode; |
| 2706 | bool truncate; |
| 2707 | int status; |
| 2708 | |
| 2709 | nfs_fattr_init(res->fattr); |
| 2710 | |
| 2711 | /* Servers should only apply open mode checks for file size changes */ |
| 2712 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2713 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2714 | |
| 2715 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2716 | /* Use that stateid */ |
| 2717 | } else if (truncate && state != NULL) { |
| 2718 | struct nfs_lockowner lockowner = { |
| 2719 | .l_owner = current->files, |
| 2720 | .l_pid = current->tgid, |
| 2721 | }; |
| 2722 | if (!nfs4_valid_open_stateid(state)) |
| 2723 | return -EBADF; |
| 2724 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2725 | &arg->stateid, &delegation_cred) == -EIO) |
| 2726 | return -EBADF; |
| 2727 | } else |
| 2728 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2729 | if (delegation_cred) |
| 2730 | msg.rpc_cred = delegation_cred; |
| 2731 | |
| 2732 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2733 | |
| 2734 | put_rpccred(delegation_cred); |
| 2735 | if (status == 0 && state != NULL) |
| 2736 | renew_lease(server, timestamp); |
| 2737 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2738 | return status; |
| 2739 | } |
| 2740 | |
| 2741 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2742 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2743 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2744 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2746 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2748 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | .iap = sattr, |
| 2750 | .server = server, |
| 2751 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2752 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | }; |
| 2754 | struct nfs_setattrres res = { |
| 2755 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2756 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | .server = server, |
| 2758 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2759 | struct nfs4_exception exception = { |
| 2760 | .state = state, |
| 2761 | .inode = inode, |
| 2762 | .stateid = &arg.stateid, |
| 2763 | }; |
| 2764 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2766 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2767 | if (ilabel) |
| 2768 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2771 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2772 | switch (err) { |
| 2773 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2774 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2775 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2776 | "applying open mode checks to " |
| 2777 | "a SETATTR that is not " |
| 2778 | "changing file size.\n", |
| 2779 | server->nfs_client->cl_hostname); |
| 2780 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2781 | if (state && !(state->state & FMODE_WRITE)) { |
| 2782 | err = -EBADF; |
| 2783 | if (sattr->ia_valid & ATTR_OPEN) |
| 2784 | err = -EACCES; |
| 2785 | goto out; |
| 2786 | } |
| 2787 | } |
| 2788 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2790 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | return err; |
| 2792 | } |
| 2793 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2794 | static bool |
| 2795 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2796 | { |
| 2797 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2798 | return false; |
| 2799 | |
| 2800 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2801 | } |
| 2802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | struct nfs4_closedata { |
| 2804 | struct inode *inode; |
| 2805 | struct nfs4_state *state; |
| 2806 | struct nfs_closeargs arg; |
| 2807 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2808 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2809 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2810 | bool roc; |
| 2811 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | }; |
| 2813 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2814 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2815 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2816 | struct nfs4_closedata *calldata = data; |
| 2817 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2818 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2819 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2820 | if (calldata->roc) |
| 2821 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2822 | nfs4_put_open_state(calldata->state); |
| 2823 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2824 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2825 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2826 | kfree(calldata); |
| 2827 | } |
| 2828 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2829 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2831 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2834 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2836 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2837 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2838 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2839 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | /* hmm. we are done with the inode, and in the process of freeing |
| 2841 | * the state_owner. we keep this around to process errors |
| 2842 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | switch (task->tk_status) { |
| 2844 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2845 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2846 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2847 | pnfs_roc_set_barrier(state->inode, |
| 2848 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2849 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2850 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2851 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2853 | case -NFS4ERR_OLD_STATEID: |
| 2854 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2856 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2857 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2858 | rpc_restart_call_prepare(task); |
| 2859 | goto out_release; |
| 2860 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2861 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2862 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2864 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2865 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2866 | goto out_release; |
| 2867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2869 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2870 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2871 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2872 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2873 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2874 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2877 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2879 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2880 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2881 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2882 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2883 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2884 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2885 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2886 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2887 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2888 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2889 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2890 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2891 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2892 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2893 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2894 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2895 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2896 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2897 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2898 | if (state->n_rdonly == 0) |
| 2899 | call_close |= is_rdonly; |
| 2900 | else if (is_rdonly) |
| 2901 | calldata->arg.fmode |= FMODE_READ; |
| 2902 | if (state->n_wronly == 0) |
| 2903 | call_close |= is_wronly; |
| 2904 | else if (is_wronly) |
| 2905 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2906 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2907 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2908 | } else if (is_rdwr) |
| 2909 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2910 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2911 | if (!nfs4_valid_open_stateid(state)) |
| 2912 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2913 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2914 | |
| 2915 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2916 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2917 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2918 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2919 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2920 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2921 | nfs_release_seqid(calldata->arg.seqid); |
| 2922 | goto out_wait; |
| 2923 | } |
| 2924 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2925 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2926 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2927 | if (calldata->roc) |
| 2928 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2929 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2930 | calldata->arg.share_access = |
| 2931 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2932 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2933 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2934 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2935 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2936 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2937 | &calldata->arg.seq_args, |
| 2938 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2939 | task) != 0) |
| 2940 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2941 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2942 | return; |
| 2943 | out_no_action: |
| 2944 | task->tk_action = NULL; |
| 2945 | out_wait: |
| 2946 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2949 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2950 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2951 | .rpc_call_done = nfs4_close_done, |
| 2952 | .rpc_release = nfs4_free_closedata, |
| 2953 | }; |
| 2954 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2955 | static bool nfs4_roc(struct inode *inode) |
| 2956 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 2957 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2958 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2959 | return pnfs_roc(inode); |
| 2960 | } |
| 2961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | /* |
| 2963 | * It is possible for data to be read/written from a mem-mapped file |
| 2964 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2965 | * This means that we can't safely call nfsv4 close on a file until |
| 2966 | * the inode is cleared. This in turn means that we are not good |
| 2967 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2968 | * share state even when we are done with one of the three share |
| 2969 | * stateid's in the inode. |
| 2970 | * |
| 2971 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2972 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2973 | 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] | 2974 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2975 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2976 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2978 | struct nfs4_state_owner *sp = state->owner; |
| 2979 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2980 | struct rpc_message msg = { |
| 2981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2982 | .rpc_cred = state->owner->so_cred, |
| 2983 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2984 | struct rpc_task_setup task_setup_data = { |
| 2985 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2986 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2987 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2988 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2989 | .flags = RPC_TASK_ASYNC, |
| 2990 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2991 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2993 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2994 | &task_setup_data.rpc_client, &msg); |
| 2995 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2996 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2998 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2999 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3000 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3002 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3004 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3005 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3006 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3007 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3008 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3009 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3010 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3011 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3012 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3013 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3014 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3015 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3016 | msg.rpc_argp = &calldata->arg; |
| 3017 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3018 | task_setup_data.callback_data = calldata; |
| 3019 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3020 | if (IS_ERR(task)) |
| 3021 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3022 | status = 0; |
| 3023 | if (wait) |
| 3024 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3025 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3026 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3027 | out_free_calldata: |
| 3028 | kfree(calldata); |
| 3029 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3030 | nfs4_put_open_state(state); |
| 3031 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3032 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3035 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3036 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3037 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3040 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3041 | |
| 3042 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3044 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3045 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3046 | |
| 3047 | nfs4_label_release_security(label); |
| 3048 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3049 | if (IS_ERR(state)) |
| 3050 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3051 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3054 | 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] | 3055 | { |
| 3056 | if (ctx->state == NULL) |
| 3057 | return; |
| 3058 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3059 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3060 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3061 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3064 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3065 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3066 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3069 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3070 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3071 | struct nfs4_server_caps_arg args = { |
| 3072 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3073 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3074 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | struct nfs4_server_caps_res res = {}; |
| 3076 | struct rpc_message msg = { |
| 3077 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3078 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | .rpc_resp = &res, |
| 3080 | }; |
| 3081 | int status; |
| 3082 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3083 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3084 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3085 | FATTR4_WORD0_LINK_SUPPORT | |
| 3086 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3087 | FATTR4_WORD0_ACLSUPPORT; |
| 3088 | if (minorversion) |
| 3089 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3090 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3091 | 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] | 3092 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3093 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3094 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3095 | case 0: |
| 3096 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3097 | res.attr_bitmask[2] = 0; |
| 3098 | break; |
| 3099 | case 1: |
| 3100 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3101 | break; |
| 3102 | case 2: |
| 3103 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3106 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3107 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3108 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3109 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3110 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3111 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3112 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3113 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | server->caps |= NFS_CAP_ACLS; |
| 3115 | if (res.has_links != 0) |
| 3116 | server->caps |= NFS_CAP_HARDLINKS; |
| 3117 | if (res.has_symlinks != 0) |
| 3118 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3119 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3120 | server->caps |= NFS_CAP_FILEID; |
| 3121 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3122 | server->caps |= NFS_CAP_MODE; |
| 3123 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3124 | server->caps |= NFS_CAP_NLINK; |
| 3125 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3126 | server->caps |= NFS_CAP_OWNER; |
| 3127 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3128 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3129 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3130 | server->caps |= NFS_CAP_ATIME; |
| 3131 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3132 | server->caps |= NFS_CAP_CTIME; |
| 3133 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3134 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3135 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3136 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3137 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3138 | #endif |
| 3139 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3140 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3141 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3142 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3143 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3144 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3145 | 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] | 3146 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3147 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3148 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3150 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | return status; |
| 3154 | } |
| 3155 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3156 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | { |
| 3158 | struct nfs4_exception exception = { }; |
| 3159 | int err; |
| 3160 | do { |
| 3161 | err = nfs4_handle_exception(server, |
| 3162 | _nfs4_server_capabilities(server, fhandle), |
| 3163 | &exception); |
| 3164 | } while (exception.retry); |
| 3165 | return err; |
| 3166 | } |
| 3167 | |
| 3168 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3169 | struct nfs_fsinfo *info) |
| 3170 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3171 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3173 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | }; |
| 3175 | struct nfs4_lookup_res res = { |
| 3176 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3177 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | .fh = fhandle, |
| 3179 | }; |
| 3180 | struct rpc_message msg = { |
| 3181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3182 | .rpc_argp = &args, |
| 3183 | .rpc_resp = &res, |
| 3184 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3185 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3186 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3187 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3188 | /* |
| 3189 | * Process the label in the upcoming getfattr |
| 3190 | */ |
| 3191 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3192 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3193 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3194 | 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] | 3195 | } |
| 3196 | |
| 3197 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3198 | struct nfs_fsinfo *info) |
| 3199 | { |
| 3200 | struct nfs4_exception exception = { }; |
| 3201 | int err; |
| 3202 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3203 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3204 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3205 | switch (err) { |
| 3206 | case 0: |
| 3207 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3208 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3209 | default: |
| 3210 | err = nfs4_handle_exception(server, err, &exception); |
| 3211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3213 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | return err; |
| 3215 | } |
| 3216 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3217 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3218 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3219 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3220 | struct rpc_auth_create_args auth_args = { |
| 3221 | .pseudoflavor = flavor, |
| 3222 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3223 | struct rpc_auth *auth; |
| 3224 | int ret; |
| 3225 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3226 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3227 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3228 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3229 | goto out; |
| 3230 | } |
| 3231 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3232 | out: |
| 3233 | return ret; |
| 3234 | } |
| 3235 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3236 | /* |
| 3237 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3238 | * |
| 3239 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3240 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3241 | * |
| 3242 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3243 | * negative errno value. |
| 3244 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3245 | 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] | 3246 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3248 | /* Per 3530bis 15.33.5 */ |
| 3249 | static const rpc_authflavor_t flav_array[] = { |
| 3250 | RPC_AUTH_GSS_KRB5P, |
| 3251 | RPC_AUTH_GSS_KRB5I, |
| 3252 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3253 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3254 | RPC_AUTH_NULL, |
| 3255 | }; |
| 3256 | int status = -EPERM; |
| 3257 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3259 | if (server->auth_info.flavor_len > 0) { |
| 3260 | /* try each flavor specified by user */ |
| 3261 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3262 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3263 | server->auth_info.flavors[i]); |
| 3264 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3265 | continue; |
| 3266 | break; |
| 3267 | } |
| 3268 | } else { |
| 3269 | /* no flavors specified by user, try default list */ |
| 3270 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3271 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3272 | flav_array[i]); |
| 3273 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3274 | continue; |
| 3275 | break; |
| 3276 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3277 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3278 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3279 | /* |
| 3280 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3281 | * to access the mount. It could also mean that we tried to mount |
| 3282 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3283 | * existing mount programs don't handle -EACCES very well so it should |
| 3284 | * be mapped to -EPERM instead. |
| 3285 | */ |
| 3286 | if (status == -EACCES) |
| 3287 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3288 | return status; |
| 3289 | } |
| 3290 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3291 | /** |
| 3292 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3293 | * @server: initialized nfs_server handle |
| 3294 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3295 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3296 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3297 | * |
| 3298 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3299 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3300 | 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] | 3301 | struct nfs_fsinfo *info, |
| 3302 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3303 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3304 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3305 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3306 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3307 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3308 | |
| 3309 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3310 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3311 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | if (status == 0) |
| 3314 | status = nfs4_server_capabilities(server, fhandle); |
| 3315 | if (status == 0) |
| 3316 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3317 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3318 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3321 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3322 | struct nfs_fsinfo *info) |
| 3323 | { |
| 3324 | int error; |
| 3325 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3326 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3327 | |
| 3328 | error = nfs4_server_capabilities(server, mntfh); |
| 3329 | if (error < 0) { |
| 3330 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3331 | return error; |
| 3332 | } |
| 3333 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3334 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3335 | if (IS_ERR(label)) |
| 3336 | return PTR_ERR(label); |
| 3337 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3338 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3339 | if (error < 0) { |
| 3340 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3341 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3345 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3346 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3347 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3348 | err_free_label: |
| 3349 | nfs4_label_free(label); |
| 3350 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3351 | return error; |
| 3352 | } |
| 3353 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3354 | /* |
| 3355 | * Get locations and (maybe) other attributes of a referral. |
| 3356 | * Note that we'll actually follow the referral later when |
| 3357 | * we detect fsid mismatch in inode revalidation |
| 3358 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3359 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3360 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3361 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3362 | { |
| 3363 | int status = -ENOMEM; |
| 3364 | struct page *page = NULL; |
| 3365 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3366 | |
| 3367 | page = alloc_page(GFP_KERNEL); |
| 3368 | if (page == NULL) |
| 3369 | goto out; |
| 3370 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3371 | if (locations == NULL) |
| 3372 | goto out; |
| 3373 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3374 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3375 | if (status != 0) |
| 3376 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3377 | |
| 3378 | /* |
| 3379 | * If the fsid didn't change, this is a migration event, not a |
| 3380 | * referral. Cause us to drop into the exception handler, which |
| 3381 | * will kick off migration recovery. |
| 3382 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3383 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3384 | dprintk("%s: server did not return a different fsid for" |
| 3385 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3386 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3387 | goto out; |
| 3388 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3389 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3390 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3391 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3392 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3393 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3394 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3395 | out: |
| 3396 | if (page) |
| 3397 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3398 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3399 | return status; |
| 3400 | } |
| 3401 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3402 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3403 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | { |
| 3405 | struct nfs4_getattr_arg args = { |
| 3406 | .fh = fhandle, |
| 3407 | .bitmask = server->attr_bitmask, |
| 3408 | }; |
| 3409 | struct nfs4_getattr_res res = { |
| 3410 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3411 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | .server = server, |
| 3413 | }; |
| 3414 | struct rpc_message msg = { |
| 3415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3416 | .rpc_argp = &args, |
| 3417 | .rpc_resp = &res, |
| 3418 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3419 | |
| 3420 | args.bitmask = nfs4_bitmask(server, label); |
| 3421 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3422 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3423 | 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] | 3424 | } |
| 3425 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3426 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3427 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | { |
| 3429 | struct nfs4_exception exception = { }; |
| 3430 | int err; |
| 3431 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3432 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3433 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3434 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | &exception); |
| 3436 | } while (exception.retry); |
| 3437 | return err; |
| 3438 | } |
| 3439 | |
| 3440 | /* |
| 3441 | * The file is not closed if it is opened due to the a request to change |
| 3442 | * the size of the file. The open call will not be needed once the |
| 3443 | * VFS layer lookup-intents are implemented. |
| 3444 | * |
| 3445 | * Close is called when the inode is destroyed. |
| 3446 | * If we haven't opened the file for O_WRONLY, we |
| 3447 | * need to in the size_change case to obtain a stateid. |
| 3448 | * |
| 3449 | * Got race? |
| 3450 | * Because OPEN is always done by name in nfsv4, it is |
| 3451 | * possible that we opened a different file by the same |
| 3452 | * name. We can recognize this race condition, but we |
| 3453 | * can't do anything about it besides returning an error. |
| 3454 | * |
| 3455 | * This will be fixed with VFS changes (lookup-intent). |
| 3456 | */ |
| 3457 | static int |
| 3458 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3459 | struct iattr *sattr) |
| 3460 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3461 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3462 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3463 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3464 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | int status; |
| 3466 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3467 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3468 | sattr->ia_valid & ATTR_SIZE && |
| 3469 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3470 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3471 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3472 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3474 | /* Deal with open(O_TRUNC) */ |
| 3475 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3476 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3477 | |
| 3478 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3479 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3480 | return 0; |
| 3481 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3482 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3483 | if (sattr->ia_valid & ATTR_FILE) { |
| 3484 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3485 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3486 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3487 | if (ctx) { |
| 3488 | cred = ctx->cred; |
| 3489 | state = ctx->state; |
| 3490 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3491 | } |
| 3492 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3493 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3494 | if (IS_ERR(label)) |
| 3495 | return PTR_ERR(label); |
| 3496 | |
| 3497 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3498 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3499 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3500 | nfs_setsecurity(inode, fattr, label); |
| 3501 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3502 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | return status; |
| 3504 | } |
| 3505 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3506 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3507 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3508 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3509 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3510 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3511 | int status; |
| 3512 | struct nfs4_lookup_arg args = { |
| 3513 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3514 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3515 | .name = name, |
| 3516 | }; |
| 3517 | struct nfs4_lookup_res res = { |
| 3518 | .server = server, |
| 3519 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3520 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3521 | .fh = fhandle, |
| 3522 | }; |
| 3523 | struct rpc_message msg = { |
| 3524 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3525 | .rpc_argp = &args, |
| 3526 | .rpc_resp = &res, |
| 3527 | }; |
| 3528 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3529 | args.bitmask = nfs4_bitmask(server, label); |
| 3530 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3531 | nfs_fattr_init(fattr); |
| 3532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3534 | 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] | 3535 | dprintk("NFS reply lookup: %d\n", status); |
| 3536 | return status; |
| 3537 | } |
| 3538 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3539 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3540 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3541 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3542 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3543 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3544 | fattr->nlink = 2; |
| 3545 | } |
| 3546 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3547 | 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] | 3548 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3549 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3550 | { |
| 3551 | struct nfs4_exception exception = { }; |
| 3552 | struct rpc_clnt *client = *clnt; |
| 3553 | int err; |
| 3554 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3555 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3556 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3557 | switch (err) { |
| 3558 | case -NFS4ERR_BADNAME: |
| 3559 | err = -ENOENT; |
| 3560 | goto out; |
| 3561 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3562 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3563 | if (err == -NFS4ERR_MOVED) |
| 3564 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3565 | goto out; |
| 3566 | case -NFS4ERR_WRONGSEC: |
| 3567 | err = -EPERM; |
| 3568 | if (client != *clnt) |
| 3569 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3570 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3571 | if (IS_ERR(client)) |
| 3572 | return PTR_ERR(client); |
| 3573 | |
| 3574 | exception.retry = 1; |
| 3575 | break; |
| 3576 | default: |
| 3577 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3578 | } |
| 3579 | } while (exception.retry); |
| 3580 | |
| 3581 | out: |
| 3582 | if (err == 0) |
| 3583 | *clnt = client; |
| 3584 | else if (client != *clnt) |
| 3585 | rpc_shutdown_client(client); |
| 3586 | |
| 3587 | return err; |
| 3588 | } |
| 3589 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3590 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3591 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3592 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3594 | int status; |
| 3595 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3596 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3597 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3598 | if (client != NFS_CLIENT(dir)) { |
| 3599 | rpc_shutdown_client(client); |
| 3600 | nfs_fixup_secinfo_attributes(fattr); |
| 3601 | } |
| 3602 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3605 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3606 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3607 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3608 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3609 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3610 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3611 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3612 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3613 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3614 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3615 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3616 | } |
| 3617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3619 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3620 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | struct nfs4_accessargs args = { |
| 3622 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3623 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3625 | struct nfs4_accessres res = { |
| 3626 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3627 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | struct rpc_message msg = { |
| 3629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3630 | .rpc_argp = &args, |
| 3631 | .rpc_resp = &res, |
| 3632 | .rpc_cred = entry->cred, |
| 3633 | }; |
| 3634 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3635 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
| 3637 | /* |
| 3638 | * Determine which access bits we want to ask for... |
| 3639 | */ |
| 3640 | if (mode & MAY_READ) |
| 3641 | args.access |= NFS4_ACCESS_READ; |
| 3642 | if (S_ISDIR(inode->i_mode)) { |
| 3643 | if (mode & MAY_WRITE) |
| 3644 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3645 | if (mode & MAY_EXEC) |
| 3646 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3647 | } else { |
| 3648 | if (mode & MAY_WRITE) |
| 3649 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3650 | if (mode & MAY_EXEC) |
| 3651 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3652 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3653 | |
| 3654 | res.fattr = nfs_alloc_fattr(); |
| 3655 | if (res.fattr == NULL) |
| 3656 | return -ENOMEM; |
| 3657 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3658 | 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] | 3659 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3660 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3661 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3663 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | return status; |
| 3665 | } |
| 3666 | |
| 3667 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3668 | { |
| 3669 | struct nfs4_exception exception = { }; |
| 3670 | int err; |
| 3671 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3672 | err = _nfs4_proc_access(inode, entry); |
| 3673 | trace_nfs4_access(inode, err); |
| 3674 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | &exception); |
| 3676 | } while (exception.retry); |
| 3677 | return err; |
| 3678 | } |
| 3679 | |
| 3680 | /* |
| 3681 | * TODO: For the time being, we don't try to get any attributes |
| 3682 | * along with any of the zero-copy operations READ, READDIR, |
| 3683 | * READLINK, WRITE. |
| 3684 | * |
| 3685 | * In the case of the first three, we want to put the GETATTR |
| 3686 | * after the read-type operation -- this is because it is hard |
| 3687 | * to predict the length of a GETATTR response in v4, and thus |
| 3688 | * align the READ data correctly. This means that the GETATTR |
| 3689 | * may end up partially falling into the page cache, and we should |
| 3690 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3691 | * To do this efficiently, we need to know the total length |
| 3692 | * of data received, which doesn't seem to be available outside |
| 3693 | * of the RPC layer. |
| 3694 | * |
| 3695 | * In the case of WRITE, we also want to put the GETATTR after |
| 3696 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3697 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | * |
| 3699 | * Both of these changes to the XDR layer would in fact be quite |
| 3700 | * minor, but I decided to leave them for a subsequent patch. |
| 3701 | */ |
| 3702 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3703 | unsigned int pgbase, unsigned int pglen) |
| 3704 | { |
| 3705 | struct nfs4_readlink args = { |
| 3706 | .fh = NFS_FH(inode), |
| 3707 | .pgbase = pgbase, |
| 3708 | .pglen = pglen, |
| 3709 | .pages = &page, |
| 3710 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3711 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | struct rpc_message msg = { |
| 3713 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3714 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3715 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | }; |
| 3717 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3718 | 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] | 3719 | } |
| 3720 | |
| 3721 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3722 | unsigned int pgbase, unsigned int pglen) |
| 3723 | { |
| 3724 | struct nfs4_exception exception = { }; |
| 3725 | int err; |
| 3726 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3727 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3728 | trace_nfs4_readlink(inode, err); |
| 3729 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | &exception); |
| 3731 | } while (exception.retry); |
| 3732 | return err; |
| 3733 | } |
| 3734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3736 | * 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] | 3737 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | static int |
| 3739 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3740 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3742 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3743 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | int status = 0; |
| 3746 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3747 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3748 | if (IS_ERR(ctx)) |
| 3749 | return PTR_ERR(ctx); |
| 3750 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3751 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3752 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3753 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3754 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | if (IS_ERR(state)) { |
| 3756 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3757 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3760 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3761 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | return status; |
| 3763 | } |
| 3764 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3765 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3767 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3768 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3770 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3772 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3773 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3774 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3776 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3777 | .rpc_argp = &args, |
| 3778 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3780 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3781 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3782 | 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] | 3783 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3784 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | return status; |
| 3786 | } |
| 3787 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3788 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | { |
| 3790 | struct nfs4_exception exception = { }; |
| 3791 | int err; |
| 3792 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3793 | err = _nfs4_proc_remove(dir, name); |
| 3794 | trace_nfs4_remove(dir, name, err); |
| 3795 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | &exception); |
| 3797 | } while (exception.retry); |
| 3798 | return err; |
| 3799 | } |
| 3800 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3801 | 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] | 3802 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3803 | struct nfs_server *server = NFS_SERVER(dir); |
| 3804 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3805 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3807 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3809 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3810 | |
| 3811 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3814 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3815 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3816 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3817 | &data->args.seq_args, |
| 3818 | &data->res.seq_res, |
| 3819 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3822 | 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] | 3823 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3824 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3825 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3826 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3827 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3828 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3829 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3830 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3831 | return 0; |
| 3832 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3833 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3836 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3837 | { |
| 3838 | struct nfs_server *server = NFS_SERVER(dir); |
| 3839 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3840 | struct nfs_renameres *res = msg->rpc_resp; |
| 3841 | |
| 3842 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3843 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3844 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3845 | } |
| 3846 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3847 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3848 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3849 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3850 | &data->args.seq_args, |
| 3851 | &data->res.seq_res, |
| 3852 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3856 | struct inode *new_dir) |
| 3857 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3858 | struct nfs_renamedata *data = task->tk_calldata; |
| 3859 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3860 | |
| 3861 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3862 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3863 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3864 | return 0; |
| 3865 | |
| 3866 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3867 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3868 | return 1; |
| 3869 | } |
| 3870 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3871 | 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] | 3872 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3873 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | struct nfs4_link_arg arg = { |
| 3875 | .fh = NFS_FH(inode), |
| 3876 | .dir_fh = NFS_FH(dir), |
| 3877 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3878 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3880 | struct nfs4_link_res res = { |
| 3881 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3882 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3883 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | struct rpc_message msg = { |
| 3885 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3886 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3887 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3889 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3891 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3892 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3893 | goto out; |
| 3894 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3895 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3896 | if (IS_ERR(res.label)) { |
| 3897 | status = PTR_ERR(res.label); |
| 3898 | goto out; |
| 3899 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3900 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3901 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3902 | 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] | 3903 | if (!status) { |
| 3904 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3905 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3906 | if (!status) |
| 3907 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3908 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3909 | |
| 3910 | |
| 3911 | nfs4_label_free(res.label); |
| 3912 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3913 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3914 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | return status; |
| 3916 | } |
| 3917 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3918 | 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] | 3919 | { |
| 3920 | struct nfs4_exception exception = { }; |
| 3921 | int err; |
| 3922 | do { |
| 3923 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3924 | _nfs4_proc_link(inode, dir, name), |
| 3925 | &exception); |
| 3926 | } while (exception.retry); |
| 3927 | return err; |
| 3928 | } |
| 3929 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3930 | struct nfs4_createdata { |
| 3931 | struct rpc_message msg; |
| 3932 | struct nfs4_create_arg arg; |
| 3933 | struct nfs4_create_res res; |
| 3934 | struct nfs_fh fh; |
| 3935 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3936 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3937 | }; |
| 3938 | |
| 3939 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3940 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3941 | { |
| 3942 | struct nfs4_createdata *data; |
| 3943 | |
| 3944 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3945 | if (data != NULL) { |
| 3946 | struct nfs_server *server = NFS_SERVER(dir); |
| 3947 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3948 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3949 | if (IS_ERR(data->label)) |
| 3950 | goto out_free; |
| 3951 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3952 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3953 | data->msg.rpc_argp = &data->arg; |
| 3954 | data->msg.rpc_resp = &data->res; |
| 3955 | data->arg.dir_fh = NFS_FH(dir); |
| 3956 | data->arg.server = server; |
| 3957 | data->arg.name = name; |
| 3958 | data->arg.attrs = sattr; |
| 3959 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3960 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3961 | data->res.server = server; |
| 3962 | data->res.fh = &data->fh; |
| 3963 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3964 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3965 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3966 | } |
| 3967 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3968 | out_free: |
| 3969 | kfree(data); |
| 3970 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3974 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3975 | 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] | 3976 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3977 | if (status == 0) { |
| 3978 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3979 | 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] | 3980 | } |
| 3981 | return status; |
| 3982 | } |
| 3983 | |
| 3984 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3985 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3986 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3987 | kfree(data); |
| 3988 | } |
| 3989 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3990 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3991 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3992 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3994 | struct nfs4_createdata *data; |
| 3995 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3997 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3998 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3999 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4000 | status = -ENOMEM; |
| 4001 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4002 | if (data == NULL) |
| 4003 | goto out; |
| 4004 | |
| 4005 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4006 | data->arg.u.symlink.pages = &page; |
| 4007 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4008 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4010 | status = nfs4_do_create(dir, dentry, data); |
| 4011 | |
| 4012 | nfs4_free_createdata(data); |
| 4013 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | return status; |
| 4015 | } |
| 4016 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4017 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4018 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | { |
| 4020 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4021 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4023 | |
| 4024 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4027 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4028 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4029 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | &exception); |
| 4031 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4032 | |
| 4033 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | return err; |
| 4035 | } |
| 4036 | |
| 4037 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4038 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4040 | struct nfs4_createdata *data; |
| 4041 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4043 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4044 | if (data == NULL) |
| 4045 | goto out; |
| 4046 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4047 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4048 | status = nfs4_do_create(dir, dentry, data); |
| 4049 | |
| 4050 | nfs4_free_createdata(data); |
| 4051 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | return status; |
| 4053 | } |
| 4054 | |
| 4055 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4056 | struct iattr *sattr) |
| 4057 | { |
| 4058 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4059 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4061 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4062 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4063 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4064 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4066 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4067 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4068 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | &exception); |
| 4070 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4071 | nfs4_label_release_security(label); |
| 4072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | return err; |
| 4074 | } |
| 4075 | |
| 4076 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4077 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4079 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | struct nfs4_readdir_arg args = { |
| 4081 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4082 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | .pgbase = 0, |
| 4084 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4085 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4086 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | }; |
| 4088 | struct nfs4_readdir_res res; |
| 4089 | struct rpc_message msg = { |
| 4090 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4091 | .rpc_argp = &args, |
| 4092 | .rpc_resp = &res, |
| 4093 | .rpc_cred = cred, |
| 4094 | }; |
| 4095 | int status; |
| 4096 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4097 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4098 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4099 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4100 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4102 | 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] | 4103 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4104 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4105 | status += args.pgbase; |
| 4106 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4107 | |
| 4108 | nfs_invalidate_atime(dir); |
| 4109 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4110 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | return status; |
| 4112 | } |
| 4113 | |
| 4114 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4115 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | { |
| 4117 | struct nfs4_exception exception = { }; |
| 4118 | int err; |
| 4119 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4120 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4121 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4122 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4123 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | &exception); |
| 4125 | } while (exception.retry); |
| 4126 | return err; |
| 4127 | } |
| 4128 | |
| 4129 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4130 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4132 | struct nfs4_createdata *data; |
| 4133 | int mode = sattr->ia_mode; |
| 4134 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4136 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4137 | if (data == NULL) |
| 4138 | goto out; |
| 4139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4141 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4143 | data->arg.ftype = NF4BLK; |
| 4144 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4145 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | } |
| 4147 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4148 | data->arg.ftype = NF4CHR; |
| 4149 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4150 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4151 | } else if (!S_ISSOCK(mode)) { |
| 4152 | status = -EINVAL; |
| 4153 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4155 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4156 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4157 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4158 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4159 | nfs4_free_createdata(data); |
| 4160 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | return status; |
| 4162 | } |
| 4163 | |
| 4164 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4165 | struct iattr *sattr, dev_t rdev) |
| 4166 | { |
| 4167 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4168 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4170 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4171 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4172 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4173 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4175 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4176 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4177 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | &exception); |
| 4179 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4180 | |
| 4181 | nfs4_label_release_security(label); |
| 4182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | return err; |
| 4184 | } |
| 4185 | |
| 4186 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4187 | struct nfs_fsstat *fsstat) |
| 4188 | { |
| 4189 | struct nfs4_statfs_arg args = { |
| 4190 | .fh = fhandle, |
| 4191 | .bitmask = server->attr_bitmask, |
| 4192 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4193 | struct nfs4_statfs_res res = { |
| 4194 | .fsstat = fsstat, |
| 4195 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | struct rpc_message msg = { |
| 4197 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4198 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4199 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | }; |
| 4201 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4202 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4203 | 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] | 4204 | } |
| 4205 | |
| 4206 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4207 | { |
| 4208 | struct nfs4_exception exception = { }; |
| 4209 | int err; |
| 4210 | do { |
| 4211 | err = nfs4_handle_exception(server, |
| 4212 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4213 | &exception); |
| 4214 | } while (exception.retry); |
| 4215 | return err; |
| 4216 | } |
| 4217 | |
| 4218 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4219 | struct nfs_fsinfo *fsinfo) |
| 4220 | { |
| 4221 | struct nfs4_fsinfo_arg args = { |
| 4222 | .fh = fhandle, |
| 4223 | .bitmask = server->attr_bitmask, |
| 4224 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4225 | struct nfs4_fsinfo_res res = { |
| 4226 | .fsinfo = fsinfo, |
| 4227 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | struct rpc_message msg = { |
| 4229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4230 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4231 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | }; |
| 4233 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4234 | 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] | 4235 | } |
| 4236 | |
| 4237 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4238 | { |
| 4239 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4240 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | int err; |
| 4242 | |
| 4243 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4244 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4245 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4246 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4247 | nfs4_set_lease_period(server->nfs_client, |
| 4248 | fsinfo->lease_time * HZ, |
| 4249 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4250 | break; |
| 4251 | } |
| 4252 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | } while (exception.retry); |
| 4254 | return err; |
| 4255 | } |
| 4256 | |
| 4257 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4258 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4259 | int error; |
| 4260 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4261 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4262 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4263 | if (error == 0) { |
| 4264 | /* block layout checks this! */ |
| 4265 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4266 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4267 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4268 | |
| 4269 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4273 | struct nfs_pathconf *pathconf) |
| 4274 | { |
| 4275 | struct nfs4_pathconf_arg args = { |
| 4276 | .fh = fhandle, |
| 4277 | .bitmask = server->attr_bitmask, |
| 4278 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4279 | struct nfs4_pathconf_res res = { |
| 4280 | .pathconf = pathconf, |
| 4281 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | struct rpc_message msg = { |
| 4283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4284 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4285 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | }; |
| 4287 | |
| 4288 | /* None of the pathconf attributes are mandatory to implement */ |
| 4289 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4290 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4291 | return 0; |
| 4292 | } |
| 4293 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4294 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4295 | 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] | 4296 | } |
| 4297 | |
| 4298 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4299 | struct nfs_pathconf *pathconf) |
| 4300 | { |
| 4301 | struct nfs4_exception exception = { }; |
| 4302 | int err; |
| 4303 | |
| 4304 | do { |
| 4305 | err = nfs4_handle_exception(server, |
| 4306 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4307 | &exception); |
| 4308 | } while (exception.retry); |
| 4309 | return err; |
| 4310 | } |
| 4311 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4312 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4313 | const struct nfs_open_context *ctx, |
| 4314 | const struct nfs_lock_context *l_ctx, |
| 4315 | fmode_t fmode) |
| 4316 | { |
| 4317 | const struct nfs_lockowner *lockowner = NULL; |
| 4318 | |
| 4319 | if (l_ctx != NULL) |
| 4320 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4321 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4322 | } |
| 4323 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4324 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4325 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4326 | const struct nfs_open_context *ctx, |
| 4327 | const struct nfs_lock_context *l_ctx, |
| 4328 | fmode_t fmode) |
| 4329 | { |
| 4330 | nfs4_stateid current_stateid; |
| 4331 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4332 | /* If the current stateid represents a lost lock, then exit */ |
| 4333 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4334 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4335 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4336 | } |
| 4337 | |
| 4338 | static bool nfs4_error_stateid_expired(int err) |
| 4339 | { |
| 4340 | switch (err) { |
| 4341 | case -NFS4ERR_DELEG_REVOKED: |
| 4342 | case -NFS4ERR_ADMIN_REVOKED: |
| 4343 | case -NFS4ERR_BAD_STATEID: |
| 4344 | case -NFS4ERR_STALE_STATEID: |
| 4345 | case -NFS4ERR_OLD_STATEID: |
| 4346 | case -NFS4ERR_OPENMODE: |
| 4347 | case -NFS4ERR_EXPIRED: |
| 4348 | return true; |
| 4349 | } |
| 4350 | return false; |
| 4351 | } |
| 4352 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4353 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4354 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4355 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4356 | } |
| 4357 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4358 | 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] | 4359 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4360 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4362 | trace_nfs4_read(hdr, task->tk_status); |
| 4363 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4364 | hdr->args.context->state, |
| 4365 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4366 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4367 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4369 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4370 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4372 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4373 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4376 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4377 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4378 | { |
| 4379 | |
| 4380 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4381 | nfs4_stateid_is_current(&args->stateid, |
| 4382 | args->context, |
| 4383 | args->lock_context, |
| 4384 | FMODE_READ)) |
| 4385 | return false; |
| 4386 | rpc_restart_call_prepare(task); |
| 4387 | return true; |
| 4388 | } |
| 4389 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4390 | 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] | 4391 | { |
| 4392 | |
| 4393 | dprintk("--> %s\n", __func__); |
| 4394 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4395 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4396 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4397 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4398 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4399 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4400 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4403 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4404 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4406 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4407 | if (!hdr->pgio_done_cb) |
| 4408 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4409 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4410 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4413 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4414 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4415 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4416 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4417 | &hdr->args.seq_args, |
| 4418 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4419 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4420 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4421 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4422 | hdr->args.lock_context, |
| 4423 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4424 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4425 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4426 | return -EIO; |
| 4427 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | } |
| 4429 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4430 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4431 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4433 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4434 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4435 | trace_nfs4_write(hdr, task->tk_status); |
| 4436 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4437 | hdr->args.context->state, |
| 4438 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4439 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4440 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4442 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4443 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4444 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4445 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4446 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4449 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4450 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4451 | { |
| 4452 | |
| 4453 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4454 | nfs4_stateid_is_current(&args->stateid, |
| 4455 | args->context, |
| 4456 | args->lock_context, |
| 4457 | FMODE_WRITE)) |
| 4458 | return false; |
| 4459 | rpc_restart_call_prepare(task); |
| 4460 | return true; |
| 4461 | } |
| 4462 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4463 | 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] | 4464 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4465 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4466 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4467 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4468 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4469 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4470 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4473 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4474 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4475 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4476 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4477 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4478 | return false; |
| 4479 | /* Otherwise, request attributes if and only if we don't hold |
| 4480 | * a delegation |
| 4481 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4482 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4483 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4484 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4485 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4486 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4488 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4489 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4490 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4491 | hdr->args.bitmask = NULL; |
| 4492 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4493 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4494 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4495 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4496 | if (!hdr->pgio_done_cb) |
| 4497 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4498 | hdr->res.server = server; |
| 4499 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4501 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4502 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4505 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4506 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4507 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4508 | &data->args.seq_args, |
| 4509 | &data->res.seq_res, |
| 4510 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4513 | 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] | 4514 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4516 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4517 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4518 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4519 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4520 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4521 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4523 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4526 | 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] | 4527 | { |
| 4528 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4529 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4530 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4531 | } |
| 4532 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4533 | 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] | 4534 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4535 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4536 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4537 | if (data->commit_done_cb == NULL) |
| 4538 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4539 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4540 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4541 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4544 | struct nfs4_renewdata { |
| 4545 | struct nfs_client *client; |
| 4546 | unsigned long timestamp; |
| 4547 | }; |
| 4548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | /* |
| 4550 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4551 | * standalone procedure for queueing an asynchronous RENEW. |
| 4552 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4553 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4554 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4555 | struct nfs4_renewdata *data = calldata; |
| 4556 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4557 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4558 | if (atomic_read(&clp->cl_count) > 1) |
| 4559 | nfs4_schedule_state_renewal(clp); |
| 4560 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4561 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4564 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4566 | struct nfs4_renewdata *data = calldata; |
| 4567 | struct nfs_client *clp = data->client; |
| 4568 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4570 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4571 | switch (task->tk_status) { |
| 4572 | case 0: |
| 4573 | break; |
| 4574 | case -NFS4ERR_LEASE_MOVED: |
| 4575 | nfs4_schedule_lease_moved_recovery(clp); |
| 4576 | break; |
| 4577 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4578 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4579 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4580 | return; |
| 4581 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4582 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4583 | return; |
| 4584 | } |
| 4585 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4587 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4590 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4591 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4592 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4593 | }; |
| 4594 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4595 | 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] | 4596 | { |
| 4597 | struct rpc_message msg = { |
| 4598 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4599 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4600 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4602 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4604 | if (renew_flags == 0) |
| 4605 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4606 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4607 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4608 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4609 | if (data == NULL) |
| 4610 | return -ENOMEM; |
| 4611 | data->client = clp; |
| 4612 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4613 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4614 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4617 | 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] | 4618 | { |
| 4619 | struct rpc_message msg = { |
| 4620 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4621 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4622 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | }; |
| 4624 | unsigned long now = jiffies; |
| 4625 | int status; |
| 4626 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4627 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | if (status < 0) |
| 4629 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4630 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | return 0; |
| 4632 | } |
| 4633 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4634 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4635 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4636 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4639 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4640 | * 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] | 4641 | * the stack. |
| 4642 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4643 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4644 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4645 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4646 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4647 | { |
| 4648 | struct page *newpage, **spages; |
| 4649 | int rc = 0; |
| 4650 | size_t len; |
| 4651 | spages = pages; |
| 4652 | |
| 4653 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4654 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4655 | newpage = alloc_page(GFP_KERNEL); |
| 4656 | |
| 4657 | if (newpage == NULL) |
| 4658 | goto unwind; |
| 4659 | memcpy(page_address(newpage), buf, len); |
| 4660 | buf += len; |
| 4661 | buflen -= len; |
| 4662 | *pages++ = newpage; |
| 4663 | rc++; |
| 4664 | } while (buflen != 0); |
| 4665 | |
| 4666 | return rc; |
| 4667 | |
| 4668 | unwind: |
| 4669 | for(; rc > 0; rc--) |
| 4670 | __free_page(spages[rc-1]); |
| 4671 | return -ENOMEM; |
| 4672 | } |
| 4673 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4674 | struct nfs4_cached_acl { |
| 4675 | int cached; |
| 4676 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4677 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | 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] | 4681 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4682 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4683 | |
| 4684 | spin_lock(&inode->i_lock); |
| 4685 | kfree(nfsi->nfs4_acl); |
| 4686 | nfsi->nfs4_acl = acl; |
| 4687 | spin_unlock(&inode->i_lock); |
| 4688 | } |
| 4689 | |
| 4690 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4691 | { |
| 4692 | nfs4_set_cached_acl(inode, NULL); |
| 4693 | } |
| 4694 | |
| 4695 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4696 | { |
| 4697 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4698 | struct nfs4_cached_acl *acl; |
| 4699 | int ret = -ENOENT; |
| 4700 | |
| 4701 | spin_lock(&inode->i_lock); |
| 4702 | acl = nfsi->nfs4_acl; |
| 4703 | if (acl == NULL) |
| 4704 | goto out; |
| 4705 | if (buf == NULL) /* user is just asking for length */ |
| 4706 | goto out_len; |
| 4707 | if (acl->cached == 0) |
| 4708 | goto out; |
| 4709 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4710 | if (acl->len > buflen) |
| 4711 | goto out; |
| 4712 | memcpy(buf, acl->data, acl->len); |
| 4713 | out_len: |
| 4714 | ret = acl->len; |
| 4715 | out: |
| 4716 | spin_unlock(&inode->i_lock); |
| 4717 | return ret; |
| 4718 | } |
| 4719 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4720 | 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] | 4721 | { |
| 4722 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4723 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4724 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4725 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4726 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4727 | if (acl == NULL) |
| 4728 | goto out; |
| 4729 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4730 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4731 | } else { |
| 4732 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4733 | if (acl == NULL) |
| 4734 | goto out; |
| 4735 | acl->cached = 0; |
| 4736 | } |
| 4737 | acl->len = acl_len; |
| 4738 | out: |
| 4739 | nfs4_set_cached_acl(inode, acl); |
| 4740 | } |
| 4741 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4742 | /* |
| 4743 | * The getxattr API returns the required buffer length when called with a |
| 4744 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4745 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4746 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4747 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4748 | * the cache. If not so, we throw away the page, and cache the required |
| 4749 | * length. The next getxattr call will then produce another round trip to |
| 4750 | * the server, this time with the input buf of the required size. |
| 4751 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4752 | 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] | 4753 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4754 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4755 | struct nfs_getaclargs args = { |
| 4756 | .fh = NFS_FH(inode), |
| 4757 | .acl_pages = pages, |
| 4758 | .acl_len = buflen, |
| 4759 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4760 | struct nfs_getaclres res = { |
| 4761 | .acl_len = buflen, |
| 4762 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4763 | struct rpc_message msg = { |
| 4764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4765 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4766 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4767 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4768 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4769 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4770 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4771 | /* As long as we're doing a round trip to the server anyway, |
| 4772 | * let's be prepared for a page of acl data. */ |
| 4773 | if (npages == 0) |
| 4774 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4775 | if (npages > ARRAY_SIZE(pages)) |
| 4776 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4777 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4778 | for (i = 0; i < npages; i++) { |
| 4779 | pages[i] = alloc_page(GFP_KERNEL); |
| 4780 | if (!pages[i]) |
| 4781 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4782 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4783 | |
| 4784 | /* for decoding across pages */ |
| 4785 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4786 | if (!res.acl_scratch) |
| 4787 | goto out_free; |
| 4788 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4789 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4790 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4791 | 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] | 4792 | __func__, buf, buflen, npages, args.acl_len); |
| 4793 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4794 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4795 | if (ret) |
| 4796 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4797 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4798 | /* Handle the case where the passed-in buffer is too short */ |
| 4799 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4800 | /* Did the user only issue a request for the acl length? */ |
| 4801 | if (buf == NULL) |
| 4802 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4803 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4804 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4805 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4806 | 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] | 4807 | if (buf) { |
| 4808 | if (res.acl_len > buflen) { |
| 4809 | ret = -ERANGE; |
| 4810 | goto out_free; |
| 4811 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4812 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4813 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4814 | out_ok: |
| 4815 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4816 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4817 | for (i = 0; i < npages; i++) |
| 4818 | if (pages[i]) |
| 4819 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4820 | if (res.acl_scratch) |
| 4821 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4822 | return ret; |
| 4823 | } |
| 4824 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4825 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4826 | { |
| 4827 | struct nfs4_exception exception = { }; |
| 4828 | ssize_t ret; |
| 4829 | do { |
| 4830 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4831 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4832 | if (ret >= 0) |
| 4833 | break; |
| 4834 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4835 | } while (exception.retry); |
| 4836 | return ret; |
| 4837 | } |
| 4838 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4839 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4840 | { |
| 4841 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4842 | int ret; |
| 4843 | |
| 4844 | if (!nfs4_server_supports_acls(server)) |
| 4845 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4846 | ret = nfs_revalidate_inode(server, inode); |
| 4847 | if (ret < 0) |
| 4848 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4849 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4850 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4851 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4852 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4853 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4854 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4855 | return ret; |
| 4856 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4857 | } |
| 4858 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4859 | 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] | 4860 | { |
| 4861 | struct nfs_server *server = NFS_SERVER(inode); |
| 4862 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4863 | struct nfs_setaclargs arg = { |
| 4864 | .fh = NFS_FH(inode), |
| 4865 | .acl_pages = pages, |
| 4866 | .acl_len = buflen, |
| 4867 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4868 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4869 | struct rpc_message msg = { |
| 4870 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4871 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4872 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4873 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4874 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4875 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4876 | |
| 4877 | if (!nfs4_server_supports_acls(server)) |
| 4878 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4879 | if (npages > ARRAY_SIZE(pages)) |
| 4880 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4881 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4882 | if (i < 0) |
| 4883 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4884 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4885 | 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] | 4886 | |
| 4887 | /* |
| 4888 | * Free each page after tx, so the only ref left is |
| 4889 | * held by the network stack |
| 4890 | */ |
| 4891 | for (; i > 0; i--) |
| 4892 | put_page(pages[i-1]); |
| 4893 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4894 | /* |
| 4895 | * Acl update can result in inode attribute update. |
| 4896 | * so mark the attribute cache invalid. |
| 4897 | */ |
| 4898 | spin_lock(&inode->i_lock); |
| 4899 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4900 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4901 | nfs_access_zap_cache(inode); |
| 4902 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4903 | return ret; |
| 4904 | } |
| 4905 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4906 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4907 | { |
| 4908 | struct nfs4_exception exception = { }; |
| 4909 | int err; |
| 4910 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4911 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4912 | trace_nfs4_set_acl(inode, err); |
| 4913 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4914 | &exception); |
| 4915 | } while (exception.retry); |
| 4916 | return err; |
| 4917 | } |
| 4918 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4919 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4920 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4921 | size_t buflen) |
| 4922 | { |
| 4923 | struct nfs_server *server = NFS_SERVER(inode); |
| 4924 | struct nfs_fattr fattr; |
| 4925 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4926 | |
| 4927 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4928 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4929 | .fh = NFS_FH(inode), |
| 4930 | .bitmask = bitmask, |
| 4931 | }; |
| 4932 | struct nfs4_getattr_res res = { |
| 4933 | .fattr = &fattr, |
| 4934 | .label = &label, |
| 4935 | .server = server, |
| 4936 | }; |
| 4937 | struct rpc_message msg = { |
| 4938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4939 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4940 | .rpc_resp = &res, |
| 4941 | }; |
| 4942 | int ret; |
| 4943 | |
| 4944 | nfs_fattr_init(&fattr); |
| 4945 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4946 | 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] | 4947 | if (ret) |
| 4948 | return ret; |
| 4949 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4950 | return -ENOENT; |
| 4951 | if (buflen < label.len) |
| 4952 | return -ERANGE; |
| 4953 | return 0; |
| 4954 | } |
| 4955 | |
| 4956 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4957 | size_t buflen) |
| 4958 | { |
| 4959 | struct nfs4_exception exception = { }; |
| 4960 | int err; |
| 4961 | |
| 4962 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4963 | return -EOPNOTSUPP; |
| 4964 | |
| 4965 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4966 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4967 | trace_nfs4_get_security_label(inode, err); |
| 4968 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4969 | &exception); |
| 4970 | } while (exception.retry); |
| 4971 | return err; |
| 4972 | } |
| 4973 | |
| 4974 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4975 | struct nfs4_label *ilabel, |
| 4976 | struct nfs_fattr *fattr, |
| 4977 | struct nfs4_label *olabel) |
| 4978 | { |
| 4979 | |
| 4980 | struct iattr sattr = {0}; |
| 4981 | struct nfs_server *server = NFS_SERVER(inode); |
| 4982 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4983 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4984 | .fh = NFS_FH(inode), |
| 4985 | .iap = &sattr, |
| 4986 | .server = server, |
| 4987 | .bitmask = bitmask, |
| 4988 | .label = ilabel, |
| 4989 | }; |
| 4990 | struct nfs_setattrres res = { |
| 4991 | .fattr = fattr, |
| 4992 | .label = olabel, |
| 4993 | .server = server, |
| 4994 | }; |
| 4995 | struct rpc_message msg = { |
| 4996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4997 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4998 | .rpc_resp = &res, |
| 4999 | }; |
| 5000 | int status; |
| 5001 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5002 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5003 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5004 | 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] | 5005 | if (status) |
| 5006 | dprintk("%s failed: %d\n", __func__, status); |
| 5007 | |
| 5008 | return status; |
| 5009 | } |
| 5010 | |
| 5011 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5012 | struct nfs4_label *ilabel, |
| 5013 | struct nfs_fattr *fattr, |
| 5014 | struct nfs4_label *olabel) |
| 5015 | { |
| 5016 | struct nfs4_exception exception = { }; |
| 5017 | int err; |
| 5018 | |
| 5019 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5020 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5021 | fattr, olabel); |
| 5022 | trace_nfs4_set_security_label(inode, err); |
| 5023 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5024 | &exception); |
| 5025 | } while (exception.retry); |
| 5026 | return err; |
| 5027 | } |
| 5028 | |
| 5029 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5030 | 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] | 5031 | { |
| 5032 | struct nfs4_label ilabel, *olabel = NULL; |
| 5033 | struct nfs_fattr fattr; |
| 5034 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5035 | int status; |
| 5036 | |
| 5037 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5038 | return -EOPNOTSUPP; |
| 5039 | |
| 5040 | nfs_fattr_init(&fattr); |
| 5041 | |
| 5042 | ilabel.pi = 0; |
| 5043 | ilabel.lfs = 0; |
| 5044 | ilabel.label = (char *)buf; |
| 5045 | ilabel.len = buflen; |
| 5046 | |
| 5047 | cred = rpc_lookup_cred(); |
| 5048 | if (IS_ERR(cred)) |
| 5049 | return PTR_ERR(cred); |
| 5050 | |
| 5051 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5052 | if (IS_ERR(olabel)) { |
| 5053 | status = -PTR_ERR(olabel); |
| 5054 | goto out; |
| 5055 | } |
| 5056 | |
| 5057 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5058 | if (status == 0) |
| 5059 | nfs_setsecurity(inode, &fattr, olabel); |
| 5060 | |
| 5061 | nfs4_label_free(olabel); |
| 5062 | out: |
| 5063 | put_rpccred(cred); |
| 5064 | return status; |
| 5065 | } |
| 5066 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5067 | |
| 5068 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5069 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5070 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5071 | { |
| 5072 | __be32 verf[2]; |
| 5073 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5074 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5075 | /* An impossible timestamp guarantees this value |
| 5076 | * will never match a generated boot time. */ |
| 5077 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5078 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5079 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5080 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5081 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5082 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5083 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5084 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5085 | } |
| 5086 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5087 | static int |
| 5088 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5089 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5090 | size_t len; |
| 5091 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5092 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5093 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5094 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5095 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5096 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5097 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5098 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5099 | 1 + |
| 5100 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5101 | 1; |
| 5102 | rcu_read_unlock(); |
| 5103 | |
| 5104 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5105 | return -EINVAL; |
| 5106 | |
| 5107 | /* |
| 5108 | * Since this string is allocated at mount time, and held until the |
| 5109 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5110 | * about a memory-reclaim deadlock. |
| 5111 | */ |
| 5112 | str = kmalloc(len, GFP_KERNEL); |
| 5113 | if (!str) |
| 5114 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5115 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5116 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5117 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5118 | clp->cl_ipaddr, |
| 5119 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5120 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5121 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5122 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5123 | clp->cl_owner_id = str; |
| 5124 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5125 | } |
| 5126 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5127 | static int |
| 5128 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5129 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5130 | size_t len; |
| 5131 | char *str; |
| 5132 | |
| 5133 | len = 10 + 10 + 1 + 10 + 1 + |
| 5134 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5135 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5136 | |
| 5137 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5138 | return -EINVAL; |
| 5139 | |
| 5140 | /* |
| 5141 | * Since this string is allocated at mount time, and held until the |
| 5142 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5143 | * about a memory-reclaim deadlock. |
| 5144 | */ |
| 5145 | str = kmalloc(len, GFP_KERNEL); |
| 5146 | if (!str) |
| 5147 | return -ENOMEM; |
| 5148 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5149 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5150 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5151 | nfs4_client_id_uniquifier, |
| 5152 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5153 | clp->cl_owner_id = str; |
| 5154 | return 0; |
| 5155 | } |
| 5156 | |
| 5157 | static int |
| 5158 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5159 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5160 | size_t len; |
| 5161 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5162 | |
| 5163 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5164 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5165 | |
| 5166 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5167 | return nfs4_init_uniquifier_client_string(clp); |
| 5168 | |
| 5169 | len = 10 + 10 + 1 + 10 + 1 + |
| 5170 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5171 | |
| 5172 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5173 | return -EINVAL; |
| 5174 | |
| 5175 | /* |
| 5176 | * Since this string is allocated at mount time, and held until the |
| 5177 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5178 | * about a memory-reclaim deadlock. |
| 5179 | */ |
| 5180 | str = kmalloc(len, GFP_KERNEL); |
| 5181 | if (!str) |
| 5182 | return -ENOMEM; |
| 5183 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5184 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5185 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5186 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5187 | clp->cl_owner_id = str; |
| 5188 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5189 | } |
| 5190 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5191 | /* |
| 5192 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5193 | * services. Advertise one based on the address family of the |
| 5194 | * clientaddr. |
| 5195 | */ |
| 5196 | static unsigned int |
| 5197 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5198 | { |
| 5199 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5200 | return scnprintf(buf, len, "tcp6"); |
| 5201 | else |
| 5202 | return scnprintf(buf, len, "tcp"); |
| 5203 | } |
| 5204 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5205 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5206 | { |
| 5207 | struct nfs4_setclientid *sc = calldata; |
| 5208 | |
| 5209 | if (task->tk_status == 0) |
| 5210 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5211 | } |
| 5212 | |
| 5213 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5214 | .rpc_call_done = nfs4_setclientid_done, |
| 5215 | }; |
| 5216 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5217 | /** |
| 5218 | * nfs4_proc_setclientid - Negotiate client ID |
| 5219 | * @clp: state data structure |
| 5220 | * @program: RPC program for NFSv4 callback service |
| 5221 | * @port: IP port number for NFS4 callback service |
| 5222 | * @cred: RPC credential to use for this call |
| 5223 | * @res: where to place the result |
| 5224 | * |
| 5225 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5226 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5227 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5228 | unsigned short port, struct rpc_cred *cred, |
| 5229 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | { |
| 5231 | nfs4_verifier sc_verifier; |
| 5232 | struct nfs4_setclientid setclientid = { |
| 5233 | .sc_verifier = &sc_verifier, |
| 5234 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5235 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | }; |
| 5237 | struct rpc_message msg = { |
| 5238 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5239 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5240 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5241 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5243 | struct rpc_task *task; |
| 5244 | struct rpc_task_setup task_setup_data = { |
| 5245 | .rpc_client = clp->cl_rpcclient, |
| 5246 | .rpc_message = &msg, |
| 5247 | .callback_ops = &nfs4_setclientid_ops, |
| 5248 | .callback_data = &setclientid, |
| 5249 | .flags = RPC_TASK_TIMEOUT, |
| 5250 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5251 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5253 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5254 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5255 | |
| 5256 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5257 | status = nfs4_init_uniform_client_string(clp); |
| 5258 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5259 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5260 | |
| 5261 | if (status) |
| 5262 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5263 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5264 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5265 | setclientid.sc_netid_len = |
| 5266 | nfs4_init_callback_netid(clp, |
| 5267 | setclientid.sc_netid, |
| 5268 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5269 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5270 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5272 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5273 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5274 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5275 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5276 | task = rpc_run_task(&task_setup_data); |
| 5277 | if (IS_ERR(task)) { |
| 5278 | status = PTR_ERR(task); |
| 5279 | goto out; |
| 5280 | } |
| 5281 | status = task->tk_status; |
| 5282 | if (setclientid.sc_cred) { |
| 5283 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5284 | put_rpccred(setclientid.sc_cred); |
| 5285 | } |
| 5286 | rpc_put_task(task); |
| 5287 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5288 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5289 | dprintk("NFS reply setclientid: %d\n", status); |
| 5290 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5293 | /** |
| 5294 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5295 | * @clp: state data structure |
| 5296 | * @res: result of a previous SETCLIENTID |
| 5297 | * @cred: RPC credential to use for this call |
| 5298 | * |
| 5299 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5300 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5301 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5302 | struct nfs4_setclientid_res *arg, |
| 5303 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | struct rpc_message msg = { |
| 5306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5307 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5308 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5309 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | int status; |
| 5311 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5312 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5313 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5314 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5315 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5316 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5317 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | return status; |
| 5319 | } |
| 5320 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5321 | struct nfs4_delegreturndata { |
| 5322 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5323 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5324 | struct nfs_fh fh; |
| 5325 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5326 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5327 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5328 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5329 | struct inode *inode; |
| 5330 | bool roc; |
| 5331 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5332 | }; |
| 5333 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5334 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5335 | { |
| 5336 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5337 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5338 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5339 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5340 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5341 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5342 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5343 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5344 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5345 | case -NFS4ERR_ADMIN_REVOKED: |
| 5346 | case -NFS4ERR_DELEG_REVOKED: |
| 5347 | case -NFS4ERR_BAD_STATEID: |
| 5348 | case -NFS4ERR_OLD_STATEID: |
| 5349 | case -NFS4ERR_STALE_STATEID: |
| 5350 | case -NFS4ERR_EXPIRED: |
| 5351 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5352 | if (data->roc) |
| 5353 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5354 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5355 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5356 | if (nfs4_async_handle_error(task, data->res.server, |
| 5357 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5358 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5359 | return; |
| 5360 | } |
| 5361 | } |
| 5362 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | static void nfs4_delegreturn_release(void *calldata) |
| 5366 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5367 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5368 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5369 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5370 | if (inode) { |
| 5371 | if (data->roc) |
| 5372 | pnfs_roc_release(inode); |
| 5373 | nfs_iput_and_deactive(inode); |
| 5374 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5375 | kfree(calldata); |
| 5376 | } |
| 5377 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5378 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5379 | { |
| 5380 | struct nfs4_delegreturndata *d_data; |
| 5381 | |
| 5382 | d_data = (struct nfs4_delegreturndata *)data; |
| 5383 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5384 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5385 | return; |
| 5386 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5387 | if (d_data->roc) |
| 5388 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5389 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5390 | nfs4_setup_sequence(d_data->res.server, |
| 5391 | &d_data->args.seq_args, |
| 5392 | &d_data->res.seq_res, |
| 5393 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5394 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5395 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5396 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5397 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5398 | .rpc_call_done = nfs4_delegreturn_done, |
| 5399 | .rpc_release = nfs4_delegreturn_release, |
| 5400 | }; |
| 5401 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5402 | 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] | 5403 | { |
| 5404 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5405 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5406 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5407 | struct rpc_message msg = { |
| 5408 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5409 | .rpc_cred = cred, |
| 5410 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5411 | struct rpc_task_setup task_setup_data = { |
| 5412 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5413 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5414 | .callback_ops = &nfs4_delegreturn_ops, |
| 5415 | .flags = RPC_TASK_ASYNC, |
| 5416 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5417 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5418 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5419 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5420 | if (data == NULL) |
| 5421 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5422 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5423 | |
| 5424 | nfs4_state_protect(server->nfs_client, |
| 5425 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5426 | &task_setup_data.rpc_client, &msg); |
| 5427 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5428 | data->args.fhandle = &data->fh; |
| 5429 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5430 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5431 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5432 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5433 | data->res.fattr = &data->fattr; |
| 5434 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5435 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5436 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5437 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5438 | data->inode = nfs_igrab_and_active(inode); |
| 5439 | if (data->inode) |
| 5440 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5441 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5442 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5443 | msg.rpc_argp = &data->args; |
| 5444 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5445 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5446 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5447 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5448 | if (!issync) |
| 5449 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5450 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5451 | if (status != 0) |
| 5452 | goto out; |
| 5453 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5454 | if (status == 0) |
| 5455 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5456 | else |
| 5457 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5458 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5459 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5460 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5463 | 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] | 5464 | { |
| 5465 | struct nfs_server *server = NFS_SERVER(inode); |
| 5466 | struct nfs4_exception exception = { }; |
| 5467 | int err; |
| 5468 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5469 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5470 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | switch (err) { |
| 5472 | case -NFS4ERR_STALE_STATEID: |
| 5473 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | case 0: |
| 5475 | return 0; |
| 5476 | } |
| 5477 | err = nfs4_handle_exception(server, err, &exception); |
| 5478 | } while (exception.retry); |
| 5479 | return err; |
| 5480 | } |
| 5481 | |
| 5482 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5483 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5484 | |
| 5485 | /* |
| 5486 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5487 | */ |
| 5488 | static unsigned long |
| 5489 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5490 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5491 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | timeout <<= 1; |
| 5493 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5494 | return NFS4_LOCK_MAXTIMEOUT; |
| 5495 | return timeout; |
| 5496 | } |
| 5497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5499 | { |
| 5500 | struct inode *inode = state->inode; |
| 5501 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5502 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5503 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5505 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5507 | struct nfs_lockt_res res = { |
| 5508 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | }; |
| 5510 | struct rpc_message msg = { |
| 5511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5512 | .rpc_argp = &arg, |
| 5513 | .rpc_resp = &res, |
| 5514 | .rpc_cred = state->owner->so_cred, |
| 5515 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | struct nfs4_lock_state *lsp; |
| 5517 | int status; |
| 5518 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5519 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5520 | status = nfs4_set_lock_state(state, request); |
| 5521 | if (status != 0) |
| 5522 | goto out; |
| 5523 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5524 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5525 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5526 | 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] | 5527 | switch (status) { |
| 5528 | case 0: |
| 5529 | request->fl_type = F_UNLCK; |
| 5530 | break; |
| 5531 | case -NFS4ERR_DENIED: |
| 5532 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5534 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5535 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5536 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | return status; |
| 5538 | } |
| 5539 | |
| 5540 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5541 | { |
| 5542 | struct nfs4_exception exception = { }; |
| 5543 | int err; |
| 5544 | |
| 5545 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5546 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5547 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5548 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | &exception); |
| 5550 | } while (exception.retry); |
| 5551 | return err; |
| 5552 | } |
| 5553 | |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5554 | static int do_vfs_lock(struct inode *inode, struct file_lock *fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | { |
Benjamin Coddington | 4f65636 | 2015-10-22 13:38:14 -0400 | [diff] [blame] | 5556 | return locks_lock_inode_wait(inode, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | } |
| 5558 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5559 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5560 | struct nfs_locku_args arg; |
| 5561 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5562 | struct nfs4_lock_state *lsp; |
| 5563 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5564 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5565 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5566 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5567 | }; |
| 5568 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5569 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5570 | struct nfs_open_context *ctx, |
| 5571 | struct nfs4_lock_state *lsp, |
| 5572 | struct nfs_seqid *seqid) |
| 5573 | { |
| 5574 | struct nfs4_unlockdata *p; |
| 5575 | struct inode *inode = lsp->ls_state->inode; |
| 5576 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5577 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5578 | if (p == NULL) |
| 5579 | return NULL; |
| 5580 | p->arg.fh = NFS_FH(inode); |
| 5581 | p->arg.fl = &p->fl; |
| 5582 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5583 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5584 | p->lsp = lsp; |
| 5585 | atomic_inc(&lsp->ls_count); |
| 5586 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5587 | p->ctx = get_nfs_open_context(ctx); |
| 5588 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5589 | p->server = NFS_SERVER(inode); |
| 5590 | return p; |
| 5591 | } |
| 5592 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5593 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5594 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5595 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5596 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5597 | nfs4_put_lock_state(calldata->lsp); |
| 5598 | put_nfs_open_context(calldata->ctx); |
| 5599 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5600 | } |
| 5601 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5602 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5603 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5604 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5605 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5606 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5607 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5608 | switch (task->tk_status) { |
| 5609 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5610 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5611 | do_vfs_lock(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5612 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5613 | &calldata->res.stateid)) |
| 5614 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5615 | case -NFS4ERR_BAD_STATEID: |
| 5616 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5617 | case -NFS4ERR_STALE_STATEID: |
| 5618 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5619 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5620 | &calldata->lsp->ls_stateid)) |
| 5621 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5622 | break; |
| 5623 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5624 | if (nfs4_async_handle_error(task, calldata->server, |
| 5625 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5626 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5627 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5628 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5631 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5632 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5633 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5635 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5636 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5637 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5638 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5639 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5640 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5641 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5642 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5643 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5644 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5645 | &calldata->res.seq_res, |
| 5646 | task) != 0) |
| 5647 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5648 | return; |
| 5649 | out_no_action: |
| 5650 | task->tk_action = NULL; |
| 5651 | out_wait: |
| 5652 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | } |
| 5654 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5655 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5656 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5657 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5658 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5659 | }; |
| 5660 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5661 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5662 | struct nfs_open_context *ctx, |
| 5663 | struct nfs4_lock_state *lsp, |
| 5664 | struct nfs_seqid *seqid) |
| 5665 | { |
| 5666 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5667 | struct rpc_message msg = { |
| 5668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5669 | .rpc_cred = ctx->cred, |
| 5670 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5671 | struct rpc_task_setup task_setup_data = { |
| 5672 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5673 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5674 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5675 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5676 | .flags = RPC_TASK_ASYNC, |
| 5677 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5678 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5679 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5680 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5681 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5682 | /* Ensure this is an unlock - when canceling a lock, the |
| 5683 | * canceled lock is passed in, and it won't be an unlock. |
| 5684 | */ |
| 5685 | fl->fl_type = F_UNLCK; |
| 5686 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5687 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5688 | if (data == NULL) { |
| 5689 | nfs_free_seqid(seqid); |
| 5690 | return ERR_PTR(-ENOMEM); |
| 5691 | } |
| 5692 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5693 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5694 | msg.rpc_argp = &data->arg; |
| 5695 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5696 | task_setup_data.callback_data = data; |
| 5697 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5698 | } |
| 5699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5701 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5702 | struct inode *inode = state->inode; |
| 5703 | struct nfs4_state_owner *sp = state->owner; |
| 5704 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5705 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5706 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5707 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5708 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5709 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5710 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5712 | status = nfs4_set_lock_state(state, request); |
| 5713 | /* Unlock _before_ we do the RPC call */ |
| 5714 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5715 | /* Exclude nfs_delegation_claim_locks() */ |
| 5716 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5717 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5718 | down_read(&nfsi->rwsem); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5719 | if (do_vfs_lock(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5720 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5721 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5722 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5723 | } |
| 5724 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5725 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5726 | if (status != 0) |
| 5727 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5728 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5729 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5730 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5731 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5732 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5733 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5734 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5735 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5736 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5737 | 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] | 5738 | status = PTR_ERR(task); |
| 5739 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5740 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5741 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5742 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5743 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5744 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5745 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5746 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5749 | struct nfs4_lockdata { |
| 5750 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5751 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5752 | struct nfs4_lock_state *lsp; |
| 5753 | struct nfs_open_context *ctx; |
| 5754 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5755 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5756 | int rpc_status; |
| 5757 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5758 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5759 | }; |
| 5760 | |
| 5761 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5762 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5763 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5764 | { |
| 5765 | struct nfs4_lockdata *p; |
| 5766 | struct inode *inode = lsp->ls_state->inode; |
| 5767 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5768 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5769 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5770 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5771 | if (p == NULL) |
| 5772 | return NULL; |
| 5773 | |
| 5774 | p->arg.fh = NFS_FH(inode); |
| 5775 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5776 | 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] | 5777 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5778 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5779 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5780 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5781 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5782 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5783 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5784 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5785 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5786 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5787 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5788 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5789 | atomic_inc(&lsp->ls_count); |
| 5790 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5791 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5792 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5793 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5794 | out_free_seqid: |
| 5795 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5796 | out_free: |
| 5797 | kfree(p); |
| 5798 | return NULL; |
| 5799 | } |
| 5800 | |
| 5801 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5802 | { |
| 5803 | struct nfs4_lockdata *data = calldata; |
| 5804 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5806 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5807 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5808 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5809 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5810 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5811 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5812 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5813 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5814 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5815 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5816 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5817 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5818 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5819 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5820 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5821 | &data->lsp->ls_stateid); |
| 5822 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5823 | if (!nfs4_valid_open_stateid(state)) { |
| 5824 | data->rpc_status = -EBADF; |
| 5825 | task->tk_action = NULL; |
| 5826 | goto out_release_open_seqid; |
| 5827 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5828 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5829 | if (nfs4_setup_sequence(data->server, |
| 5830 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5831 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5832 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5833 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5834 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5835 | nfs_release_seqid(data->arg.open_seqid); |
| 5836 | out_release_lock_seqid: |
| 5837 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5838 | out_wait: |
| 5839 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5840 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5841 | } |
| 5842 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5843 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5844 | { |
| 5845 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5846 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5847 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5848 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5849 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5850 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5851 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5852 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5853 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5854 | switch (task->tk_status) { |
| 5855 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5856 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5857 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5858 | if (data->arg.new_lock) { |
| 5859 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5860 | if (do_vfs_lock(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5861 | rpc_restart_call_prepare(task); |
| 5862 | break; |
| 5863 | } |
| 5864 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5865 | if (data->arg.new_lock_owner != 0) { |
| 5866 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5867 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5868 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5869 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5870 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5871 | break; |
| 5872 | case -NFS4ERR_BAD_STATEID: |
| 5873 | case -NFS4ERR_OLD_STATEID: |
| 5874 | case -NFS4ERR_STALE_STATEID: |
| 5875 | case -NFS4ERR_EXPIRED: |
| 5876 | if (data->arg.new_lock_owner != 0) { |
| 5877 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5878 | &lsp->ls_state->open_stateid)) |
| 5879 | rpc_restart_call_prepare(task); |
| 5880 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5881 | &lsp->ls_stateid)) |
| 5882 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5883 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5884 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | static void nfs4_lock_release(void *calldata) |
| 5888 | { |
| 5889 | struct nfs4_lockdata *data = calldata; |
| 5890 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5891 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5892 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5893 | if (data->cancelled != 0) { |
| 5894 | struct rpc_task *task; |
| 5895 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5896 | data->arg.lock_seqid); |
| 5897 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5898 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5899 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5900 | } else |
| 5901 | nfs_free_seqid(data->arg.lock_seqid); |
| 5902 | nfs4_put_lock_state(data->lsp); |
| 5903 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5904 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5905 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5906 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5910 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5911 | .rpc_call_done = nfs4_lock_done, |
| 5912 | .rpc_release = nfs4_lock_release, |
| 5913 | }; |
| 5914 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5915 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5916 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5917 | switch (error) { |
| 5918 | case -NFS4ERR_ADMIN_REVOKED: |
| 5919 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5920 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5921 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5922 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5923 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5924 | break; |
| 5925 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5926 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5927 | case -NFS4ERR_EXPIRED: |
| 5928 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5929 | }; |
| 5930 | } |
| 5931 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5932 | 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] | 5933 | { |
| 5934 | struct nfs4_lockdata *data; |
| 5935 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5936 | struct rpc_message msg = { |
| 5937 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5938 | .rpc_cred = state->owner->so_cred, |
| 5939 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5940 | struct rpc_task_setup task_setup_data = { |
| 5941 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5942 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5943 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5944 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5945 | .flags = RPC_TASK_ASYNC, |
| 5946 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5947 | int ret; |
| 5948 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5949 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5950 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5951 | fl->fl_u.nfs4_fl.owner, |
| 5952 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5953 | if (data == NULL) |
| 5954 | return -ENOMEM; |
| 5955 | if (IS_SETLKW(cmd)) |
| 5956 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5957 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5958 | msg.rpc_argp = &data->arg; |
| 5959 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5960 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5961 | if (recovery_type > NFS_LOCK_NEW) { |
| 5962 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5963 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5964 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5965 | } else |
| 5966 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5967 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5968 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5969 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5970 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5971 | if (ret == 0) { |
| 5972 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5973 | if (ret) |
| 5974 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5975 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5976 | } else |
| 5977 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5978 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5979 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5980 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5981 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5985 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5986 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5987 | struct nfs4_exception exception = { |
| 5988 | .inode = state->inode, |
| 5989 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5990 | int err; |
| 5991 | |
| 5992 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5993 | /* Cache the lock if possible... */ |
| 5994 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5995 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5996 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5997 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5998 | break; |
| 5999 | nfs4_handle_exception(server, err, &exception); |
| 6000 | } while (exception.retry); |
| 6001 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6005 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6006 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6007 | struct nfs4_exception exception = { |
| 6008 | .inode = state->inode, |
| 6009 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6010 | int err; |
| 6011 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6012 | err = nfs4_set_lock_state(state, request); |
| 6013 | if (err != 0) |
| 6014 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6015 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6016 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6017 | return 0; |
| 6018 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6019 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6020 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6021 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6022 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6023 | switch (err) { |
| 6024 | default: |
| 6025 | goto out; |
| 6026 | case -NFS4ERR_GRACE: |
| 6027 | case -NFS4ERR_DELAY: |
| 6028 | nfs4_handle_exception(server, err, &exception); |
| 6029 | err = 0; |
| 6030 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6031 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6032 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6033 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6036 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6037 | /** |
| 6038 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6039 | * |
| 6040 | * @state: NFSv4 state for an inode |
| 6041 | * |
| 6042 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6043 | * Otherwise a negative NFS4ERR value is returned. |
| 6044 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6045 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6046 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6047 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6048 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6049 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6050 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6051 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6052 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6053 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6054 | |
| 6055 | status = nfs41_test_stateid(server, |
| 6056 | &lsp->ls_stateid, |
| 6057 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6058 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6059 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6060 | /* Free the stateid unless the server |
| 6061 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 6062 | if (status != -NFS4ERR_BAD_STATEID) |
| 6063 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6064 | &lsp->ls_stateid, |
| 6065 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6066 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6067 | ret = status; |
| 6068 | } |
| 6069 | } |
| 6070 | }; |
| 6071 | |
| 6072 | return ret; |
| 6073 | } |
| 6074 | |
| 6075 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6076 | { |
| 6077 | int status = NFS_OK; |
| 6078 | |
| 6079 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6080 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6081 | if (status != NFS_OK) |
| 6082 | status = nfs4_lock_expired(state, request); |
| 6083 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6084 | } |
| 6085 | #endif |
| 6086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6088 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6089 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6090 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6091 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6092 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6093 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6094 | if ((fl_flags & FL_POSIX) && |
| 6095 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6096 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6097 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6098 | status = nfs4_set_lock_state(state, request); |
| 6099 | if (status != 0) |
| 6100 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6101 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6102 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6103 | if (status < 0) |
| 6104 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6105 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6106 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6107 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6108 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6109 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6110 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6111 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6112 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6113 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6114 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6115 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6116 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6117 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6118 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6119 | out: |
| 6120 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | return status; |
| 6122 | } |
| 6123 | |
| 6124 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6125 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6126 | struct nfs4_exception exception = { |
| 6127 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6128 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | int err; |
| 6131 | |
| 6132 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6133 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6134 | if (err == -NFS4ERR_DENIED) |
| 6135 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6136 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6137 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6138 | } while (exception.retry); |
| 6139 | return err; |
| 6140 | } |
| 6141 | |
| 6142 | static int |
| 6143 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6144 | { |
| 6145 | struct nfs_open_context *ctx; |
| 6146 | struct nfs4_state *state; |
| 6147 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6148 | int status; |
| 6149 | |
| 6150 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6151 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | state = ctx->state; |
| 6153 | |
| 6154 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6155 | return -EINVAL; |
| 6156 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6157 | if (IS_GETLK(cmd)) { |
| 6158 | if (state != NULL) |
| 6159 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6160 | return 0; |
| 6161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6162 | |
| 6163 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6164 | return -EINVAL; |
| 6165 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6166 | if (request->fl_type == F_UNLCK) { |
| 6167 | if (state != NULL) |
| 6168 | return nfs4_proc_unlck(state, cmd, request); |
| 6169 | return 0; |
| 6170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6172 | if (state == NULL) |
| 6173 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6174 | /* |
| 6175 | * Don't rely on the VFS having checked the file open mode, |
| 6176 | * since it won't do this for flock() locks. |
| 6177 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6178 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6179 | case F_RDLCK: |
| 6180 | if (!(filp->f_mode & FMODE_READ)) |
| 6181 | return -EBADF; |
| 6182 | break; |
| 6183 | case F_WRLCK: |
| 6184 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6185 | return -EBADF; |
| 6186 | } |
| 6187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | do { |
| 6189 | status = nfs4_proc_setlk(state, cmd, request); |
| 6190 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6191 | break; |
| 6192 | timeout = nfs4_set_lock_task_retry(timeout); |
| 6193 | status = -ERESTARTSYS; |
| 6194 | if (signalled()) |
| 6195 | break; |
| 6196 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | return status; |
| 6198 | } |
| 6199 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6200 | 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] | 6201 | { |
| 6202 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6203 | int err; |
| 6204 | |
| 6205 | err = nfs4_set_lock_state(state, fl); |
| 6206 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6207 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6208 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6209 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6210 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6211 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6212 | struct nfs_release_lockowner_data { |
| 6213 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6214 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6215 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6216 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6217 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6218 | }; |
| 6219 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6220 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6221 | { |
| 6222 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6223 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6224 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6225 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6226 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6227 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6231 | { |
| 6232 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6233 | struct nfs_server *server = data->server; |
| 6234 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6235 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6236 | |
| 6237 | switch (task->tk_status) { |
| 6238 | case 0: |
| 6239 | renew_lease(server, data->timestamp); |
| 6240 | break; |
| 6241 | case -NFS4ERR_STALE_CLIENTID: |
| 6242 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6243 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6244 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6245 | case -NFS4ERR_LEASE_MOVED: |
| 6246 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6247 | if (nfs4_async_handle_error(task, server, |
| 6248 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6249 | rpc_restart_call_prepare(task); |
| 6250 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6251 | } |
| 6252 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6253 | static void nfs4_release_lockowner_release(void *calldata) |
| 6254 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6255 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6256 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6257 | kfree(calldata); |
| 6258 | } |
| 6259 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6260 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6261 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6262 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6263 | .rpc_release = nfs4_release_lockowner_release, |
| 6264 | }; |
| 6265 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6266 | static void |
| 6267 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6268 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6269 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6270 | struct rpc_message msg = { |
| 6271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6272 | }; |
| 6273 | |
| 6274 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6275 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6276 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6277 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6278 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6279 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6280 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6281 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6282 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6283 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6284 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6285 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6286 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6287 | msg.rpc_resp = &data->res; |
| 6288 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6289 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6290 | } |
| 6291 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6292 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6293 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6294 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6295 | struct dentry *unused, struct inode *inode, |
| 6296 | const char *key, const void *buf, |
| 6297 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6298 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6299 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6300 | } |
| 6301 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6302 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6303 | struct dentry *unused, struct inode *inode, |
| 6304 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6305 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6306 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6309 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6310 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6311 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6314 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6315 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6316 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6317 | struct dentry *unused, struct inode *inode, |
| 6318 | const char *key, const void *buf, |
| 6319 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6320 | { |
| 6321 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6322 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6323 | |
| 6324 | return -EOPNOTSUPP; |
| 6325 | } |
| 6326 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6327 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6328 | struct dentry *unused, struct inode *inode, |
| 6329 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6330 | { |
| 6331 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6332 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6333 | return -EOPNOTSUPP; |
| 6334 | } |
| 6335 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6336 | static ssize_t |
| 6337 | 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] | 6338 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6339 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6340 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6341 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6342 | len = security_inode_listsecurity(inode, list, list_len); |
| 6343 | if (list_len && len > list_len) |
| 6344 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6345 | } |
| 6346 | return len; |
| 6347 | } |
| 6348 | |
| 6349 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6350 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6351 | .get = nfs4_xattr_get_nfs4_label, |
| 6352 | .set = nfs4_xattr_set_nfs4_label, |
| 6353 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6354 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6355 | #else |
| 6356 | |
| 6357 | static ssize_t |
| 6358 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6359 | { |
| 6360 | return 0; |
| 6361 | } |
| 6362 | |
| 6363 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6364 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6365 | /* |
| 6366 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6367 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6368 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6369 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6370 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6371 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6372 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6373 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6374 | return; |
| 6375 | |
| 6376 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6377 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6378 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6379 | fattr->nlink = 2; |
| 6380 | } |
| 6381 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6382 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6383 | const struct qstr *name, |
| 6384 | struct nfs4_fs_locations *fs_locations, |
| 6385 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6386 | { |
| 6387 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6388 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6389 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6390 | }; |
| 6391 | struct nfs4_fs_locations_arg args = { |
| 6392 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6393 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6394 | .page = page, |
| 6395 | .bitmask = bitmask, |
| 6396 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6397 | struct nfs4_fs_locations_res res = { |
| 6398 | .fs_locations = fs_locations, |
| 6399 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6400 | struct rpc_message msg = { |
| 6401 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6402 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6403 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6404 | }; |
| 6405 | int status; |
| 6406 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6407 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6408 | |
| 6409 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6410 | * is not supported */ |
| 6411 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6412 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6413 | else |
| 6414 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6415 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6416 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6417 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6418 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6419 | 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] | 6420 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6421 | return status; |
| 6422 | } |
| 6423 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6424 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6425 | const struct qstr *name, |
| 6426 | struct nfs4_fs_locations *fs_locations, |
| 6427 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6428 | { |
| 6429 | struct nfs4_exception exception = { }; |
| 6430 | int err; |
| 6431 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6432 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6433 | fs_locations, page); |
| 6434 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6435 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6436 | &exception); |
| 6437 | } while (exception.retry); |
| 6438 | return err; |
| 6439 | } |
| 6440 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6441 | /* |
| 6442 | * This operation also signals the server that this client is |
| 6443 | * performing migration recovery. The server can stop returning |
| 6444 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6445 | * appended to this compound to identify the client ID which is |
| 6446 | * performing recovery. |
| 6447 | */ |
| 6448 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6449 | struct nfs4_fs_locations *locations, |
| 6450 | struct page *page, struct rpc_cred *cred) |
| 6451 | { |
| 6452 | struct nfs_server *server = NFS_SERVER(inode); |
| 6453 | struct rpc_clnt *clnt = server->client; |
| 6454 | u32 bitmask[2] = { |
| 6455 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6456 | }; |
| 6457 | struct nfs4_fs_locations_arg args = { |
| 6458 | .clientid = server->nfs_client->cl_clientid, |
| 6459 | .fh = NFS_FH(inode), |
| 6460 | .page = page, |
| 6461 | .bitmask = bitmask, |
| 6462 | .migration = 1, /* skip LOOKUP */ |
| 6463 | .renew = 1, /* append RENEW */ |
| 6464 | }; |
| 6465 | struct nfs4_fs_locations_res res = { |
| 6466 | .fs_locations = locations, |
| 6467 | .migration = 1, |
| 6468 | .renew = 1, |
| 6469 | }; |
| 6470 | struct rpc_message msg = { |
| 6471 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6472 | .rpc_argp = &args, |
| 6473 | .rpc_resp = &res, |
| 6474 | .rpc_cred = cred, |
| 6475 | }; |
| 6476 | unsigned long now = jiffies; |
| 6477 | int status; |
| 6478 | |
| 6479 | nfs_fattr_init(&locations->fattr); |
| 6480 | locations->server = server; |
| 6481 | locations->nlocations = 0; |
| 6482 | |
| 6483 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6484 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6485 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6486 | &args.seq_args, &res.seq_res); |
| 6487 | if (status) |
| 6488 | return status; |
| 6489 | |
| 6490 | renew_lease(server, now); |
| 6491 | return 0; |
| 6492 | } |
| 6493 | |
| 6494 | #ifdef CONFIG_NFS_V4_1 |
| 6495 | |
| 6496 | /* |
| 6497 | * This operation also signals the server that this client is |
| 6498 | * performing migration recovery. The server can stop asserting |
| 6499 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6500 | * performing this operation is identified in the SEQUENCE |
| 6501 | * operation in this compound. |
| 6502 | * |
| 6503 | * When the client supports GETATTR(fs_locations_info), it can |
| 6504 | * be plumbed in here. |
| 6505 | */ |
| 6506 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6507 | struct nfs4_fs_locations *locations, |
| 6508 | struct page *page, struct rpc_cred *cred) |
| 6509 | { |
| 6510 | struct nfs_server *server = NFS_SERVER(inode); |
| 6511 | struct rpc_clnt *clnt = server->client; |
| 6512 | u32 bitmask[2] = { |
| 6513 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6514 | }; |
| 6515 | struct nfs4_fs_locations_arg args = { |
| 6516 | .fh = NFS_FH(inode), |
| 6517 | .page = page, |
| 6518 | .bitmask = bitmask, |
| 6519 | .migration = 1, /* skip LOOKUP */ |
| 6520 | }; |
| 6521 | struct nfs4_fs_locations_res res = { |
| 6522 | .fs_locations = locations, |
| 6523 | .migration = 1, |
| 6524 | }; |
| 6525 | struct rpc_message msg = { |
| 6526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6527 | .rpc_argp = &args, |
| 6528 | .rpc_resp = &res, |
| 6529 | .rpc_cred = cred, |
| 6530 | }; |
| 6531 | int status; |
| 6532 | |
| 6533 | nfs_fattr_init(&locations->fattr); |
| 6534 | locations->server = server; |
| 6535 | locations->nlocations = 0; |
| 6536 | |
| 6537 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6538 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6539 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6540 | &args.seq_args, &res.seq_res); |
| 6541 | if (status == NFS4_OK && |
| 6542 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6543 | status = -NFS4ERR_LEASE_MOVED; |
| 6544 | return status; |
| 6545 | } |
| 6546 | |
| 6547 | #endif /* CONFIG_NFS_V4_1 */ |
| 6548 | |
| 6549 | /** |
| 6550 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6551 | * @inode: inode on FSID that is migrating |
| 6552 | * @locations: result of query |
| 6553 | * @page: buffer |
| 6554 | * @cred: credential to use for this operation |
| 6555 | * |
| 6556 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6557 | * operation failed, or a negative errno if a local error occurred. |
| 6558 | * |
| 6559 | * On success, "locations" is filled in, but if the server has |
| 6560 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6561 | * asserted. |
| 6562 | * |
| 6563 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6564 | * from this client that require migration recovery. |
| 6565 | */ |
| 6566 | int nfs4_proc_get_locations(struct inode *inode, |
| 6567 | struct nfs4_fs_locations *locations, |
| 6568 | struct page *page, struct rpc_cred *cred) |
| 6569 | { |
| 6570 | struct nfs_server *server = NFS_SERVER(inode); |
| 6571 | struct nfs_client *clp = server->nfs_client; |
| 6572 | const struct nfs4_mig_recovery_ops *ops = |
| 6573 | clp->cl_mvops->mig_recovery_ops; |
| 6574 | struct nfs4_exception exception = { }; |
| 6575 | int status; |
| 6576 | |
| 6577 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6578 | (unsigned long long)server->fsid.major, |
| 6579 | (unsigned long long)server->fsid.minor, |
| 6580 | clp->cl_hostname); |
| 6581 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6582 | |
| 6583 | do { |
| 6584 | status = ops->get_locations(inode, locations, page, cred); |
| 6585 | if (status != -NFS4ERR_DELAY) |
| 6586 | break; |
| 6587 | nfs4_handle_exception(server, status, &exception); |
| 6588 | } while (exception.retry); |
| 6589 | return status; |
| 6590 | } |
| 6591 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6592 | /* |
| 6593 | * This operation also signals the server that this client is |
| 6594 | * performing "lease moved" recovery. The server can stop |
| 6595 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6596 | * is appended to this compound to identify the client ID which is |
| 6597 | * performing recovery. |
| 6598 | */ |
| 6599 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6600 | { |
| 6601 | struct nfs_server *server = NFS_SERVER(inode); |
| 6602 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6603 | struct rpc_clnt *clnt = server->client; |
| 6604 | struct nfs4_fsid_present_arg args = { |
| 6605 | .fh = NFS_FH(inode), |
| 6606 | .clientid = clp->cl_clientid, |
| 6607 | .renew = 1, /* append RENEW */ |
| 6608 | }; |
| 6609 | struct nfs4_fsid_present_res res = { |
| 6610 | .renew = 1, |
| 6611 | }; |
| 6612 | struct rpc_message msg = { |
| 6613 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6614 | .rpc_argp = &args, |
| 6615 | .rpc_resp = &res, |
| 6616 | .rpc_cred = cred, |
| 6617 | }; |
| 6618 | unsigned long now = jiffies; |
| 6619 | int status; |
| 6620 | |
| 6621 | res.fh = nfs_alloc_fhandle(); |
| 6622 | if (res.fh == NULL) |
| 6623 | return -ENOMEM; |
| 6624 | |
| 6625 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6626 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6627 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6628 | &args.seq_args, &res.seq_res); |
| 6629 | nfs_free_fhandle(res.fh); |
| 6630 | if (status) |
| 6631 | return status; |
| 6632 | |
| 6633 | do_renew_lease(clp, 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 "lease moved" recovery. The server can stop asserting |
| 6642 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6643 | * this operation is identified in the SEQUENCE operation in this |
| 6644 | * compound. |
| 6645 | */ |
| 6646 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6647 | { |
| 6648 | struct nfs_server *server = NFS_SERVER(inode); |
| 6649 | struct rpc_clnt *clnt = server->client; |
| 6650 | struct nfs4_fsid_present_arg args = { |
| 6651 | .fh = NFS_FH(inode), |
| 6652 | }; |
| 6653 | struct nfs4_fsid_present_res res = { |
| 6654 | }; |
| 6655 | struct rpc_message msg = { |
| 6656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6657 | .rpc_argp = &args, |
| 6658 | .rpc_resp = &res, |
| 6659 | .rpc_cred = cred, |
| 6660 | }; |
| 6661 | int status; |
| 6662 | |
| 6663 | res.fh = nfs_alloc_fhandle(); |
| 6664 | if (res.fh == NULL) |
| 6665 | return -ENOMEM; |
| 6666 | |
| 6667 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6668 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6669 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6670 | &args.seq_args, &res.seq_res); |
| 6671 | nfs_free_fhandle(res.fh); |
| 6672 | if (status == NFS4_OK && |
| 6673 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6674 | status = -NFS4ERR_LEASE_MOVED; |
| 6675 | return status; |
| 6676 | } |
| 6677 | |
| 6678 | #endif /* CONFIG_NFS_V4_1 */ |
| 6679 | |
| 6680 | /** |
| 6681 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6682 | * @inode: inode on FSID to check |
| 6683 | * @cred: credential to use for this operation |
| 6684 | * |
| 6685 | * Server indicates whether the FSID is present, moved, or not |
| 6686 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6687 | * condition for this client ID. |
| 6688 | * |
| 6689 | * Returns NFS4_OK if the FSID is present on this server, |
| 6690 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6691 | * NFS4ERR code if some error occurred on the server, or a |
| 6692 | * negative errno if a local failure occurred. |
| 6693 | */ |
| 6694 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6695 | { |
| 6696 | struct nfs_server *server = NFS_SERVER(inode); |
| 6697 | struct nfs_client *clp = server->nfs_client; |
| 6698 | const struct nfs4_mig_recovery_ops *ops = |
| 6699 | clp->cl_mvops->mig_recovery_ops; |
| 6700 | struct nfs4_exception exception = { }; |
| 6701 | int status; |
| 6702 | |
| 6703 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6704 | (unsigned long long)server->fsid.major, |
| 6705 | (unsigned long long)server->fsid.minor, |
| 6706 | clp->cl_hostname); |
| 6707 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6708 | |
| 6709 | do { |
| 6710 | status = ops->fsid_present(inode, cred); |
| 6711 | if (status != -NFS4ERR_DELAY) |
| 6712 | break; |
| 6713 | nfs4_handle_exception(server, status, &exception); |
| 6714 | } while (exception.retry); |
| 6715 | return status; |
| 6716 | } |
| 6717 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6718 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6719 | * If 'use_integrity' is true and the state managment nfs_client |
| 6720 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6721 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6722 | * Considerations sections. Otherwise, just use the user cred with the |
| 6723 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6724 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6725 | 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] | 6726 | { |
| 6727 | int status; |
| 6728 | struct nfs4_secinfo_arg args = { |
| 6729 | .dir_fh = NFS_FH(dir), |
| 6730 | .name = name, |
| 6731 | }; |
| 6732 | struct nfs4_secinfo_res res = { |
| 6733 | .flavors = flavors, |
| 6734 | }; |
| 6735 | struct rpc_message msg = { |
| 6736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6737 | .rpc_argp = &args, |
| 6738 | .rpc_resp = &res, |
| 6739 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6740 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6741 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6742 | |
| 6743 | if (use_integrity) { |
| 6744 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6745 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6746 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6747 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6748 | |
| 6749 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6750 | |
| 6751 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6752 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6753 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6754 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6755 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6756 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6757 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6758 | if (cred) |
| 6759 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6760 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6761 | return status; |
| 6762 | } |
| 6763 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6764 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6765 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6766 | { |
| 6767 | struct nfs4_exception exception = { }; |
| 6768 | int err; |
| 6769 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6770 | err = -NFS4ERR_WRONGSEC; |
| 6771 | |
| 6772 | /* try to use integrity protection with machine cred */ |
| 6773 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6774 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6775 | |
| 6776 | /* |
| 6777 | * if unable to use integrity protection, or SECINFO with |
| 6778 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6779 | * disallowed by spec, but exists in deployed servers) use |
| 6780 | * the current filesystem's rpc_client and the user cred. |
| 6781 | */ |
| 6782 | if (err == -NFS4ERR_WRONGSEC) |
| 6783 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6784 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6785 | trace_nfs4_secinfo(dir, name, err); |
| 6786 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6787 | &exception); |
| 6788 | } while (exception.retry); |
| 6789 | return err; |
| 6790 | } |
| 6791 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6792 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6793 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6794 | * Check the exchange flags returned by the server for invalid flags, having |
| 6795 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6796 | * DS flags set. |
| 6797 | */ |
| 6798 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6799 | { |
| 6800 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6801 | goto out_inval; |
| 6802 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6803 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6804 | goto out_inval; |
| 6805 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6806 | goto out_inval; |
| 6807 | return NFS_OK; |
| 6808 | out_inval: |
| 6809 | return -NFS4ERR_INVAL; |
| 6810 | } |
| 6811 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6812 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6813 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6814 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6815 | { |
| 6816 | if (a->server_scope_sz == b->server_scope_sz && |
| 6817 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6818 | return true; |
| 6819 | |
| 6820 | return false; |
| 6821 | } |
| 6822 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6823 | static void |
| 6824 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6825 | { |
| 6826 | } |
| 6827 | |
| 6828 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6829 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6830 | }; |
| 6831 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6832 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6833 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6834 | * |
| 6835 | * The 4.1 client currently uses the same TCP connection for the |
| 6836 | * fore and backchannel. |
| 6837 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6838 | static |
| 6839 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6840 | struct rpc_xprt *xprt, |
| 6841 | struct nfs_client *clp, |
| 6842 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6843 | { |
| 6844 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6845 | struct nfs41_bind_conn_to_session_args args = { |
| 6846 | .client = clp, |
| 6847 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6848 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6849 | struct nfs41_bind_conn_to_session_res res; |
| 6850 | struct rpc_message msg = { |
| 6851 | .rpc_proc = |
| 6852 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6853 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6854 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6855 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6856 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6857 | struct rpc_task_setup task_setup_data = { |
| 6858 | .rpc_client = clnt, |
| 6859 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6860 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6861 | .rpc_message = &msg, |
| 6862 | .flags = RPC_TASK_TIMEOUT, |
| 6863 | }; |
| 6864 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6865 | |
| 6866 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6867 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6868 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 6869 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 6870 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6871 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6872 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 6873 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 6874 | args.dir = NFS4_CDFC4_FORE; |
| 6875 | |
| 6876 | task = rpc_run_task(&task_setup_data); |
| 6877 | if (!IS_ERR(task)) { |
| 6878 | status = task->tk_status; |
| 6879 | rpc_put_task(task); |
| 6880 | } else |
| 6881 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6882 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6883 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6884 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6885 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6886 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6887 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6888 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6889 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6890 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6891 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6892 | __func__); |
| 6893 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6894 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6895 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6896 | 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] | 6897 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6898 | __func__); |
| 6899 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6900 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6901 | } |
| 6902 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6903 | out: |
| 6904 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6905 | return status; |
| 6906 | } |
| 6907 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6908 | struct rpc_bind_conn_calldata { |
| 6909 | struct nfs_client *clp; |
| 6910 | struct rpc_cred *cred; |
| 6911 | }; |
| 6912 | |
| 6913 | static int |
| 6914 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 6915 | struct rpc_xprt *xprt, |
| 6916 | void *calldata) |
| 6917 | { |
| 6918 | struct rpc_bind_conn_calldata *p = calldata; |
| 6919 | |
| 6920 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 6921 | } |
| 6922 | |
| 6923 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 6924 | { |
| 6925 | struct rpc_bind_conn_calldata data = { |
| 6926 | .clp = clp, |
| 6927 | .cred = cred, |
| 6928 | }; |
| 6929 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 6930 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 6931 | } |
| 6932 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6933 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6934 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6935 | * 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] | 6936 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6937 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6938 | .how = SP4_MACH_CRED, |
| 6939 | .enforce.u.words = { |
| 6940 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6941 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6942 | 1 << (OP_CREATE_SESSION - 32) | |
| 6943 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6944 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6945 | }, |
| 6946 | .allow.u.words = { |
| 6947 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6948 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6949 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6950 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6951 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6952 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6953 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6954 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6955 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6956 | 1 << (OP_FREE_STATEID - 32) | |
| 6957 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6958 | } |
| 6959 | }; |
| 6960 | |
| 6961 | /* |
| 6962 | * Select the state protection mode for client `clp' given the server results |
| 6963 | * from exchange_id in `sp'. |
| 6964 | * |
| 6965 | * Returns 0 on success, negative errno otherwise. |
| 6966 | */ |
| 6967 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6968 | struct nfs41_state_protection *sp) |
| 6969 | { |
| 6970 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6971 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6972 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6973 | 1 << (OP_CREATE_SESSION - 32) | |
| 6974 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6975 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6976 | }; |
| 6977 | unsigned int i; |
| 6978 | |
| 6979 | if (sp->how == SP4_MACH_CRED) { |
| 6980 | /* Print state protect result */ |
| 6981 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6982 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6983 | if (test_bit(i, sp->enforce.u.longs)) |
| 6984 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6985 | if (test_bit(i, sp->allow.u.longs)) |
| 6986 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6987 | } |
| 6988 | |
| 6989 | /* make sure nothing is on enforce list that isn't supported */ |
| 6990 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6991 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6992 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6993 | return -EINVAL; |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | /* |
| 6998 | * Minimal mode - state operations are allowed to use machine |
| 6999 | * credential. Note this already happens by default, so the |
| 7000 | * client doesn't have to do anything more than the negotiation. |
| 7001 | * |
| 7002 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7003 | * we're already using the machine cred for exchange_id |
| 7004 | * and will never use a different cred. |
| 7005 | */ |
| 7006 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7007 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7008 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7009 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7010 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7011 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7012 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7013 | } else { |
| 7014 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7015 | return -EINVAL; |
| 7016 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7017 | |
| 7018 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7019 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7020 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7021 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7022 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7023 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7024 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7025 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7026 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7027 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7028 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7029 | &clp->cl_sp4_flags); |
| 7030 | } |
| 7031 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7032 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7033 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7034 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7035 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7036 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7037 | |
| 7038 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7039 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7040 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7041 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7042 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7043 | |
| 7044 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7045 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7046 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7047 | } |
| 7048 | |
| 7049 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7050 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7051 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7052 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | return 0; |
| 7056 | } |
| 7057 | |
| 7058 | /* |
| 7059 | * _nfs4_proc_exchange_id() |
| 7060 | * |
| 7061 | * Wrapper for EXCHANGE_ID operation. |
| 7062 | */ |
| 7063 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7064 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7065 | { |
| 7066 | nfs4_verifier verifier; |
| 7067 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 7068 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7069 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7070 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 7071 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7072 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7073 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7074 | #else |
| 7075 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7076 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7077 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7078 | }; |
| 7079 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7080 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7081 | }; |
| 7082 | int status; |
| 7083 | struct rpc_message msg = { |
| 7084 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 7085 | .rpc_argp = &args, |
| 7086 | .rpc_resp = &res, |
| 7087 | .rpc_cred = cred, |
| 7088 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7089 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 7090 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7091 | |
| 7092 | status = nfs4_init_uniform_client_string(clp); |
| 7093 | if (status) |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7094 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7095 | |
| 7096 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7097 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7098 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7099 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7100 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7101 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7102 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7103 | status = -ENOMEM; |
| 7104 | goto out; |
| 7105 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7106 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7107 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7108 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7109 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7110 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7111 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7112 | } |
| 7113 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7114 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7115 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7116 | status = -ENOMEM; |
| 7117 | goto out_server_scope; |
| 7118 | } |
| 7119 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7120 | switch (sp4_how) { |
| 7121 | case SP4_NONE: |
| 7122 | args.state_protect.how = SP4_NONE; |
| 7123 | break; |
| 7124 | |
| 7125 | case SP4_MACH_CRED: |
| 7126 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 7127 | break; |
| 7128 | |
| 7129 | default: |
| 7130 | /* unsupported! */ |
| 7131 | WARN_ON_ONCE(1); |
| 7132 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7133 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7134 | } |
| 7135 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7136 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7137 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7138 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7139 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7140 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7141 | if (status == 0) |
| 7142 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 7143 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7144 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7145 | clp->cl_clientid = res.clientid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7146 | clp->cl_exchange_flags = res.flags; |
| 7147 | /* Client ID is not confirmed */ |
| 7148 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7149 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7150 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7151 | clp->cl_seqid = res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7152 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7153 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7154 | kfree(clp->cl_serverowner); |
| 7155 | clp->cl_serverowner = res.server_owner; |
| 7156 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7157 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7158 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7159 | kfree(clp->cl_implid); |
| 7160 | clp->cl_implid = res.impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7161 | res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7162 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7163 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7164 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7165 | res.server_scope)) { |
| 7166 | dprintk("%s: server_scope mismatch detected\n", |
| 7167 | __func__); |
| 7168 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7169 | kfree(clp->cl_serverscope); |
| 7170 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7171 | } |
| 7172 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7173 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7174 | clp->cl_serverscope = res.server_scope; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7175 | res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7176 | } |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7177 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7178 | |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7179 | out_impl_id: |
| 7180 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7181 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7182 | kfree(res.server_scope); |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7183 | out_server_owner: |
| 7184 | kfree(res.server_owner); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7185 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7186 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7187 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7188 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7189 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7190 | clp->cl_implid->date.seconds, |
| 7191 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7192 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7193 | return status; |
| 7194 | } |
| 7195 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7196 | /* |
| 7197 | * nfs4_proc_exchange_id() |
| 7198 | * |
| 7199 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7200 | * |
| 7201 | * Since the clientid has expired, all compounds using sessions |
| 7202 | * associated with the stale clientid will be returning |
| 7203 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7204 | * be in some phase of session reset. |
| 7205 | * |
| 7206 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7207 | */ |
| 7208 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7209 | { |
| 7210 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7211 | int status; |
| 7212 | |
| 7213 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7214 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7215 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 7216 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 7217 | if (!status) |
| 7218 | return 0; |
| 7219 | } |
| 7220 | |
| 7221 | /* try SP4_NONE */ |
| 7222 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 7223 | } |
| 7224 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7225 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7226 | struct rpc_cred *cred) |
| 7227 | { |
| 7228 | struct rpc_message msg = { |
| 7229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7230 | .rpc_argp = clp, |
| 7231 | .rpc_cred = cred, |
| 7232 | }; |
| 7233 | int status; |
| 7234 | |
| 7235 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7236 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7237 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7238 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7239 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7240 | return status; |
| 7241 | } |
| 7242 | |
| 7243 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7244 | struct rpc_cred *cred) |
| 7245 | { |
| 7246 | unsigned int loop; |
| 7247 | int ret; |
| 7248 | |
| 7249 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7250 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7251 | switch (ret) { |
| 7252 | case -NFS4ERR_DELAY: |
| 7253 | case -NFS4ERR_CLIENTID_BUSY: |
| 7254 | ssleep(1); |
| 7255 | break; |
| 7256 | default: |
| 7257 | return ret; |
| 7258 | } |
| 7259 | } |
| 7260 | return 0; |
| 7261 | } |
| 7262 | |
| 7263 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7264 | { |
| 7265 | struct rpc_cred *cred; |
| 7266 | int ret = 0; |
| 7267 | |
| 7268 | if (clp->cl_mvops->minor_version < 1) |
| 7269 | goto out; |
| 7270 | if (clp->cl_exchange_flags == 0) |
| 7271 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7272 | if (clp->cl_preserve_clid) |
| 7273 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7274 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7275 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7276 | if (cred) |
| 7277 | put_rpccred(cred); |
| 7278 | switch (ret) { |
| 7279 | case 0: |
| 7280 | case -NFS4ERR_STALE_CLIENTID: |
| 7281 | clp->cl_exchange_flags = 0; |
| 7282 | } |
| 7283 | out: |
| 7284 | return ret; |
| 7285 | } |
| 7286 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7287 | struct nfs4_get_lease_time_data { |
| 7288 | struct nfs4_get_lease_time_args *args; |
| 7289 | struct nfs4_get_lease_time_res *res; |
| 7290 | struct nfs_client *clp; |
| 7291 | }; |
| 7292 | |
| 7293 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7294 | void *calldata) |
| 7295 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7296 | struct nfs4_get_lease_time_data *data = |
| 7297 | (struct nfs4_get_lease_time_data *)calldata; |
| 7298 | |
| 7299 | dprintk("--> %s\n", __func__); |
| 7300 | /* just setup sequence, do not trigger session recovery |
| 7301 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7302 | nfs41_setup_sequence(data->clp->cl_session, |
| 7303 | &data->args->la_seq_args, |
| 7304 | &data->res->lr_seq_res, |
| 7305 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7306 | dprintk("<-- %s\n", __func__); |
| 7307 | } |
| 7308 | |
| 7309 | /* |
| 7310 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7311 | * from sequence operation or clientid errors. |
| 7312 | */ |
| 7313 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7314 | { |
| 7315 | struct nfs4_get_lease_time_data *data = |
| 7316 | (struct nfs4_get_lease_time_data *)calldata; |
| 7317 | |
| 7318 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7319 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7320 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7321 | switch (task->tk_status) { |
| 7322 | case -NFS4ERR_DELAY: |
| 7323 | case -NFS4ERR_GRACE: |
| 7324 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7325 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7326 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7327 | /* fall through */ |
| 7328 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7329 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7330 | return; |
| 7331 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7332 | dprintk("<-- %s\n", __func__); |
| 7333 | } |
| 7334 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7335 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7336 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7337 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7338 | }; |
| 7339 | |
| 7340 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7341 | { |
| 7342 | struct rpc_task *task; |
| 7343 | struct nfs4_get_lease_time_args args; |
| 7344 | struct nfs4_get_lease_time_res res = { |
| 7345 | .lr_fsinfo = fsinfo, |
| 7346 | }; |
| 7347 | struct nfs4_get_lease_time_data data = { |
| 7348 | .args = &args, |
| 7349 | .res = &res, |
| 7350 | .clp = clp, |
| 7351 | }; |
| 7352 | struct rpc_message msg = { |
| 7353 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7354 | .rpc_argp = &args, |
| 7355 | .rpc_resp = &res, |
| 7356 | }; |
| 7357 | struct rpc_task_setup task_setup = { |
| 7358 | .rpc_client = clp->cl_rpcclient, |
| 7359 | .rpc_message = &msg, |
| 7360 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7361 | .callback_data = &data, |
| 7362 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7363 | }; |
| 7364 | int status; |
| 7365 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7366 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7367 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7368 | dprintk("--> %s\n", __func__); |
| 7369 | task = rpc_run_task(&task_setup); |
| 7370 | |
| 7371 | if (IS_ERR(task)) |
| 7372 | status = PTR_ERR(task); |
| 7373 | else { |
| 7374 | status = task->tk_status; |
| 7375 | rpc_put_task(task); |
| 7376 | } |
| 7377 | dprintk("<-- %s return %d\n", __func__, status); |
| 7378 | |
| 7379 | return status; |
| 7380 | } |
| 7381 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7382 | /* |
| 7383 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7384 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7385 | * use them. |
| 7386 | * |
| 7387 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7388 | * always set csa_cachethis to FALSE because the current implementation |
| 7389 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7390 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7391 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7392 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7393 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7394 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7395 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7396 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7397 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7398 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7399 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7400 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7401 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7402 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7403 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7404 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7405 | |
| 7406 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7407 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7408 | __func__, |
| 7409 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7410 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7411 | |
| 7412 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7413 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7414 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7415 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7416 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | f4f58ed | 2016-01-23 14:12:52 -0500 | [diff] [blame] | 7417 | args->bc_attrs.max_reqs = NFS41_BC_MAX_CALLBACKS; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7418 | |
| 7419 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7420 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7421 | __func__, |
| 7422 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7423 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7424 | args->bc_attrs.max_reqs); |
| 7425 | } |
| 7426 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7427 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7428 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7429 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7430 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7431 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7432 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7433 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7434 | return -EINVAL; |
| 7435 | /* |
| 7436 | * Our requested max_ops is the minimum we need; we're not |
| 7437 | * prepared to break up compounds into smaller pieces than that. |
| 7438 | * So, no point even trying to continue if the server won't |
| 7439 | * cooperate: |
| 7440 | */ |
| 7441 | if (rcvd->max_ops < sent->max_ops) |
| 7442 | return -EINVAL; |
| 7443 | if (rcvd->max_reqs == 0) |
| 7444 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7445 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7446 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7447 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7448 | } |
| 7449 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7450 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7451 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7452 | { |
| 7453 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7454 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7455 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7456 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7457 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7458 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7459 | return -EINVAL; |
| 7460 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7461 | return -EINVAL; |
| 7462 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7463 | return -EINVAL; |
| 7464 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7465 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7466 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7467 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7468 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7469 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7470 | return 0; |
| 7471 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7472 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7473 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7474 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7475 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7476 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7477 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7478 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7479 | if (ret) |
| 7480 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7481 | return nfs4_verify_back_channel_attrs(args, res); |
| 7482 | } |
| 7483 | |
| 7484 | static void nfs4_update_session(struct nfs4_session *session, |
| 7485 | struct nfs41_create_session_res *res) |
| 7486 | { |
| 7487 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7488 | /* Mark client id and session as being confirmed */ |
| 7489 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7490 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7491 | session->flags = res->flags; |
| 7492 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7493 | if (res->flags & SESSION4_BACK_CHAN) |
| 7494 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7495 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7496 | } |
| 7497 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7498 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7499 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7500 | { |
| 7501 | struct nfs4_session *session = clp->cl_session; |
| 7502 | struct nfs41_create_session_args args = { |
| 7503 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7504 | .clientid = clp->cl_clientid, |
| 7505 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7506 | .cb_program = NFS4_CALLBACK, |
| 7507 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7508 | struct nfs41_create_session_res res; |
| 7509 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7510 | struct rpc_message msg = { |
| 7511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7512 | .rpc_argp = &args, |
| 7513 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7514 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7515 | }; |
| 7516 | int status; |
| 7517 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7518 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7519 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7520 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7521 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7522 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7523 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7524 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7525 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7526 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7527 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7528 | if (clp->cl_seqid == res.seqid) |
| 7529 | clp->cl_seqid++; |
| 7530 | if (status) |
| 7531 | goto out; |
| 7532 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7533 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7534 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7535 | return status; |
| 7536 | } |
| 7537 | |
| 7538 | /* |
| 7539 | * Issues a CREATE_SESSION operation to the server. |
| 7540 | * It is the responsibility of the caller to verify the session is |
| 7541 | * expired before calling this routine. |
| 7542 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7543 | 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] | 7544 | { |
| 7545 | int status; |
| 7546 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7547 | struct nfs4_session *session = clp->cl_session; |
| 7548 | |
| 7549 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7550 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7551 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7552 | if (status) |
| 7553 | goto out; |
| 7554 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7555 | /* Init or reset the session slot tables */ |
| 7556 | status = nfs4_setup_session_slot_tables(session); |
| 7557 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7558 | if (status) |
| 7559 | goto out; |
| 7560 | |
| 7561 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7562 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7563 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7564 | out: |
| 7565 | dprintk("<-- %s\n", __func__); |
| 7566 | return status; |
| 7567 | } |
| 7568 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7569 | /* |
| 7570 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7571 | * The caller must serialize access to this routine. |
| 7572 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7573 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7574 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7575 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7576 | struct rpc_message msg = { |
| 7577 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7578 | .rpc_argp = session, |
| 7579 | .rpc_cred = cred, |
| 7580 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7581 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7582 | |
| 7583 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7584 | |
| 7585 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7586 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7587 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7588 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7589 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7590 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7591 | |
| 7592 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7593 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7594 | "Session has been destroyed regardless...\n", status); |
| 7595 | |
| 7596 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7597 | return status; |
| 7598 | } |
| 7599 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7600 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7601 | * Renew the cl_session lease. |
| 7602 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7603 | struct nfs4_sequence_data { |
| 7604 | struct nfs_client *clp; |
| 7605 | struct nfs4_sequence_args args; |
| 7606 | struct nfs4_sequence_res res; |
| 7607 | }; |
| 7608 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7609 | static void nfs41_sequence_release(void *data) |
| 7610 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7611 | struct nfs4_sequence_data *calldata = data; |
| 7612 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7613 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7614 | if (atomic_read(&clp->cl_count) > 1) |
| 7615 | nfs4_schedule_state_renewal(clp); |
| 7616 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7617 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7618 | } |
| 7619 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7620 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7621 | { |
| 7622 | switch(task->tk_status) { |
| 7623 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7624 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7625 | return -EAGAIN; |
| 7626 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7627 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7628 | } |
| 7629 | return 0; |
| 7630 | } |
| 7631 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7632 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7633 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7634 | struct nfs4_sequence_data *calldata = data; |
| 7635 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7636 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7637 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7638 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7639 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7640 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7641 | if (task->tk_status < 0) { |
| 7642 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7643 | if (atomic_read(&clp->cl_count) == 1) |
| 7644 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7645 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7646 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7647 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7648 | return; |
| 7649 | } |
| 7650 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7651 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7652 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7653 | dprintk("<-- %s\n", __func__); |
| 7654 | } |
| 7655 | |
| 7656 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7657 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7658 | struct nfs4_sequence_data *calldata = data; |
| 7659 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7660 | struct nfs4_sequence_args *args; |
| 7661 | struct nfs4_sequence_res *res; |
| 7662 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7663 | args = task->tk_msg.rpc_argp; |
| 7664 | res = task->tk_msg.rpc_resp; |
| 7665 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7666 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7670 | .rpc_call_done = nfs41_sequence_call_done, |
| 7671 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7672 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7673 | }; |
| 7674 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7675 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7676 | struct rpc_cred *cred, |
| 7677 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7678 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7679 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7680 | struct rpc_message msg = { |
| 7681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7682 | .rpc_cred = cred, |
| 7683 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7684 | struct rpc_task_setup task_setup_data = { |
| 7685 | .rpc_client = clp->cl_rpcclient, |
| 7686 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7687 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7688 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7689 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7690 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7691 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7692 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7693 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7694 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7695 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7696 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7697 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7698 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7699 | if (is_privileged) |
| 7700 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7701 | msg.rpc_argp = &calldata->args; |
| 7702 | msg.rpc_resp = &calldata->res; |
| 7703 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7704 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7705 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7706 | return rpc_run_task(&task_setup_data); |
| 7707 | } |
| 7708 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7709 | 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] | 7710 | { |
| 7711 | struct rpc_task *task; |
| 7712 | int ret = 0; |
| 7713 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7714 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7715 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7716 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7717 | if (IS_ERR(task)) |
| 7718 | ret = PTR_ERR(task); |
| 7719 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7720 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7721 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7722 | return ret; |
| 7723 | } |
| 7724 | |
| 7725 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7726 | { |
| 7727 | struct rpc_task *task; |
| 7728 | int ret; |
| 7729 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7730 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7731 | if (IS_ERR(task)) { |
| 7732 | ret = PTR_ERR(task); |
| 7733 | goto out; |
| 7734 | } |
| 7735 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 7736 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7737 | ret = task->tk_status; |
| 7738 | rpc_put_task(task); |
| 7739 | out: |
| 7740 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7741 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7742 | } |
| 7743 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7744 | struct nfs4_reclaim_complete_data { |
| 7745 | struct nfs_client *clp; |
| 7746 | struct nfs41_reclaim_complete_args arg; |
| 7747 | struct nfs41_reclaim_complete_res res; |
| 7748 | }; |
| 7749 | |
| 7750 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7751 | { |
| 7752 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7753 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7754 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7755 | &calldata->arg.seq_args, |
| 7756 | &calldata->res.seq_res, |
| 7757 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7758 | } |
| 7759 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7760 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7761 | { |
| 7762 | switch(task->tk_status) { |
| 7763 | case 0: |
| 7764 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7765 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7766 | break; |
| 7767 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7768 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7769 | /* fall through */ |
| 7770 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7771 | return -EAGAIN; |
| 7772 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7773 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7774 | } |
| 7775 | return 0; |
| 7776 | } |
| 7777 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7778 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7779 | { |
| 7780 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7781 | struct nfs_client *clp = calldata->clp; |
| 7782 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7783 | |
| 7784 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7785 | if (!nfs41_sequence_done(task, res)) |
| 7786 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7787 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7788 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7789 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7790 | rpc_restart_call_prepare(task); |
| 7791 | return; |
| 7792 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7793 | dprintk("<-- %s\n", __func__); |
| 7794 | } |
| 7795 | |
| 7796 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7797 | { |
| 7798 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7799 | |
| 7800 | kfree(calldata); |
| 7801 | } |
| 7802 | |
| 7803 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7804 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7805 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7806 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7807 | }; |
| 7808 | |
| 7809 | /* |
| 7810 | * Issue a global reclaim complete. |
| 7811 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7812 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7813 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7814 | { |
| 7815 | struct nfs4_reclaim_complete_data *calldata; |
| 7816 | struct rpc_task *task; |
| 7817 | struct rpc_message msg = { |
| 7818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7819 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7820 | }; |
| 7821 | struct rpc_task_setup task_setup_data = { |
| 7822 | .rpc_client = clp->cl_rpcclient, |
| 7823 | .rpc_message = &msg, |
| 7824 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7825 | .flags = RPC_TASK_ASYNC, |
| 7826 | }; |
| 7827 | int status = -ENOMEM; |
| 7828 | |
| 7829 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7830 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7831 | if (calldata == NULL) |
| 7832 | goto out; |
| 7833 | calldata->clp = clp; |
| 7834 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7835 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7836 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7837 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7838 | msg.rpc_argp = &calldata->arg; |
| 7839 | msg.rpc_resp = &calldata->res; |
| 7840 | task_setup_data.callback_data = calldata; |
| 7841 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7842 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7843 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7844 | goto out; |
| 7845 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7846 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7847 | if (status == 0) |
| 7848 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7849 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7850 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7851 | out: |
| 7852 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7853 | return status; |
| 7854 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7855 | |
| 7856 | static void |
| 7857 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7858 | { |
| 7859 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7860 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7861 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7862 | |
| 7863 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7864 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 7865 | &lgp->res.seq_res, task); |
| 7866 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7867 | } |
| 7868 | |
| 7869 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7870 | { |
| 7871 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7872 | |
| 7873 | dprintk("--> %s\n", __func__); |
| 7874 | nfs41_sequence_done(task, &lgp->res.seq_res); |
| 7875 | dprintk("<-- %s\n", __func__); |
| 7876 | } |
| 7877 | |
| 7878 | static int |
| 7879 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 7880 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 7881 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7882 | struct inode *inode = lgp->args.inode; |
| 7883 | struct nfs_server *server = NFS_SERVER(inode); |
| 7884 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 7885 | int nfs4err = task->tk_status; |
| 7886 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 7887 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7888 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7889 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7890 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 7891 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7892 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7893 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 7894 | |
| 7895 | /* |
| 7896 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 7897 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 7898 | * retry go inband. |
| 7899 | */ |
| 7900 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7901 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 7902 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7903 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7904 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 7905 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 7906 | */ |
| 7907 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7908 | status = -EOVERFLOW; |
| 7909 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7910 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7911 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7912 | * (or clients) writing to the same RAID stripe except when |
| 7913 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7914 | * |
| 7915 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 7916 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7917 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7918 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7919 | if (lgp->args.minlength == 0) { |
| 7920 | status = -EOVERFLOW; |
| 7921 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7922 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 7923 | status = -EBUSY; |
| 7924 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7925 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7926 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 7927 | break; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7928 | case -NFS4ERR_EXPIRED: |
| 7929 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7930 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7931 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 7932 | lo = NFS_I(inode)->layout; |
| 7933 | /* If the open stateid was bad, then recover it. */ |
| 7934 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 7935 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7936 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7937 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7938 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7939 | break; |
| 7940 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7941 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 7942 | /* |
| 7943 | * Mark the bad layout state as invalid, then retry |
| 7944 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 7945 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 7946 | spin_unlock(&inode->i_lock); |
| 7947 | pnfs_free_lseg_list(&head); |
| 7948 | status = -EAGAIN; |
| 7949 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7950 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7951 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 7952 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 7953 | if (!status) { |
| 7954 | if (exception->retry) |
| 7955 | status = -EAGAIN; |
| 7956 | else |
| 7957 | status = err; |
| 7958 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7959 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7960 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7961 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7962 | } |
| 7963 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7964 | static size_t max_response_pages(struct nfs_server *server) |
| 7965 | { |
| 7966 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7967 | return nfs_page_array_len(0, max_resp_sz); |
| 7968 | } |
| 7969 | |
| 7970 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7971 | { |
| 7972 | int i; |
| 7973 | |
| 7974 | if (!pages) |
| 7975 | return; |
| 7976 | |
| 7977 | for (i = 0; i < size; i++) { |
| 7978 | if (!pages[i]) |
| 7979 | break; |
| 7980 | __free_page(pages[i]); |
| 7981 | } |
| 7982 | kfree(pages); |
| 7983 | } |
| 7984 | |
| 7985 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7986 | { |
| 7987 | struct page **pages; |
| 7988 | int i; |
| 7989 | |
| 7990 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7991 | if (!pages) { |
| 7992 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7993 | return NULL; |
| 7994 | } |
| 7995 | |
| 7996 | for (i = 0; i < size; i++) { |
| 7997 | pages[i] = alloc_page(gfp_flags); |
| 7998 | if (!pages[i]) { |
| 7999 | dprintk("%s: failed to allocate page\n", __func__); |
| 8000 | nfs4_free_pages(pages, size); |
| 8001 | return NULL; |
| 8002 | } |
| 8003 | } |
| 8004 | |
| 8005 | return pages; |
| 8006 | } |
| 8007 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8008 | static void nfs4_layoutget_release(void *calldata) |
| 8009 | { |
| 8010 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8011 | struct inode *inode = lgp->args.inode; |
| 8012 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8013 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8014 | |
| 8015 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8016 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8017 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8018 | put_nfs_open_context(lgp->args.ctx); |
| 8019 | kfree(calldata); |
| 8020 | dprintk("<-- %s\n", __func__); |
| 8021 | } |
| 8022 | |
| 8023 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8024 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8025 | .rpc_call_done = nfs4_layoutget_done, |
| 8026 | .rpc_release = nfs4_layoutget_release, |
| 8027 | }; |
| 8028 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8029 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8030 | 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] | 8031 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8032 | struct inode *inode = lgp->args.inode; |
| 8033 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8034 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8035 | struct rpc_task *task; |
| 8036 | struct rpc_message msg = { |
| 8037 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8038 | .rpc_argp = &lgp->args, |
| 8039 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8040 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8041 | }; |
| 8042 | struct rpc_task_setup task_setup_data = { |
| 8043 | .rpc_client = server->client, |
| 8044 | .rpc_message = &msg, |
| 8045 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8046 | .callback_data = lgp, |
| 8047 | .flags = RPC_TASK_ASYNC, |
| 8048 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8049 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8050 | struct nfs4_exception exception = { |
| 8051 | .inode = inode, |
| 8052 | .timeout = *timeout, |
| 8053 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8054 | int status = 0; |
| 8055 | |
| 8056 | dprintk("--> %s\n", __func__); |
| 8057 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8058 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8059 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8060 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8061 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8062 | if (!lgp->args.layout.pages) { |
| 8063 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8064 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8065 | } |
| 8066 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8067 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8068 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8069 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8070 | 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] | 8071 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8072 | task = rpc_run_task(&task_setup_data); |
| 8073 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8074 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8075 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8076 | if (status == 0) { |
| 8077 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8078 | *timeout = exception.timeout; |
| 8079 | } |
| 8080 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8081 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8082 | &lgp->args.range, |
| 8083 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8084 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8085 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8086 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8087 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8088 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8089 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8090 | rpc_put_task(task); |
| 8091 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8092 | if (status) |
| 8093 | return ERR_PTR(status); |
| 8094 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8095 | } |
| 8096 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8097 | static void |
| 8098 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8099 | { |
| 8100 | struct nfs4_layoutreturn *lrp = calldata; |
| 8101 | |
| 8102 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8103 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8104 | &lrp->args.seq_args, |
| 8105 | &lrp->res.seq_res, |
| 8106 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8110 | { |
| 8111 | struct nfs4_layoutreturn *lrp = calldata; |
| 8112 | struct nfs_server *server; |
| 8113 | |
| 8114 | dprintk("--> %s\n", __func__); |
| 8115 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8116 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8117 | return; |
| 8118 | |
| 8119 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8120 | switch (task->tk_status) { |
| 8121 | default: |
| 8122 | task->tk_status = 0; |
| 8123 | case 0: |
| 8124 | break; |
| 8125 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8126 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8127 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8128 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8129 | return; |
| 8130 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8131 | dprintk("<-- %s\n", __func__); |
| 8132 | } |
| 8133 | |
| 8134 | static void nfs4_layoutreturn_release(void *calldata) |
| 8135 | { |
| 8136 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8137 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8138 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8139 | |
| 8140 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8141 | spin_lock(&lo->plh_inode->i_lock); |
Jeff Layton | 6d597e1 | 2016-05-17 12:28:42 -0400 | [diff] [blame] | 8142 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, &lrp->args.range, |
| 8143 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 45fcc7b | 2016-07-24 12:26:34 -0400 | [diff] [blame] | 8144 | if (lrp->res.lrs_present && pnfs_layout_is_valid(lo)) |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8145 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8146 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8147 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8148 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8149 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8150 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8151 | kfree(calldata); |
| 8152 | dprintk("<-- %s\n", __func__); |
| 8153 | } |
| 8154 | |
| 8155 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8156 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8157 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8158 | .rpc_release = nfs4_layoutreturn_release, |
| 8159 | }; |
| 8160 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8161 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8162 | { |
| 8163 | struct rpc_task *task; |
| 8164 | struct rpc_message msg = { |
| 8165 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8166 | .rpc_argp = &lrp->args, |
| 8167 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8168 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8169 | }; |
| 8170 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8171 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8172 | .rpc_message = &msg, |
| 8173 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8174 | .callback_data = lrp, |
| 8175 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8176 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8177 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8178 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8179 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8180 | &task_setup_data.rpc_client, &msg); |
| 8181 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8182 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8183 | if (!sync) { |
| 8184 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8185 | if (!lrp->inode) { |
| 8186 | nfs4_layoutreturn_release(lrp); |
| 8187 | return -EAGAIN; |
| 8188 | } |
| 8189 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8190 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8191 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8192 | task = rpc_run_task(&task_setup_data); |
| 8193 | if (IS_ERR(task)) |
| 8194 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8195 | if (sync) |
| 8196 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8197 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8198 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8199 | rpc_put_task(task); |
| 8200 | return status; |
| 8201 | } |
| 8202 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8203 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8204 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8205 | struct pnfs_device *pdev, |
| 8206 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8207 | { |
| 8208 | struct nfs4_getdeviceinfo_args args = { |
| 8209 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8210 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8211 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8212 | }; |
| 8213 | struct nfs4_getdeviceinfo_res res = { |
| 8214 | .pdev = pdev, |
| 8215 | }; |
| 8216 | struct rpc_message msg = { |
| 8217 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8218 | .rpc_argp = &args, |
| 8219 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8220 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8221 | }; |
| 8222 | int status; |
| 8223 | |
| 8224 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8225 | 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] | 8226 | if (res.notification & ~args.notify_types) |
| 8227 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8228 | if (res.notification != args.notify_types) |
| 8229 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8230 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8231 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8232 | |
| 8233 | return status; |
| 8234 | } |
| 8235 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8236 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8237 | struct pnfs_device *pdev, |
| 8238 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8239 | { |
| 8240 | struct nfs4_exception exception = { }; |
| 8241 | int err; |
| 8242 | |
| 8243 | do { |
| 8244 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8245 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8246 | &exception); |
| 8247 | } while (exception.retry); |
| 8248 | return err; |
| 8249 | } |
| 8250 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8251 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8252 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8253 | { |
| 8254 | struct nfs4_layoutcommit_data *data = calldata; |
| 8255 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8256 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8257 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8258 | nfs41_setup_sequence(session, |
| 8259 | &data->args.seq_args, |
| 8260 | &data->res.seq_res, |
| 8261 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | static void |
| 8265 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8266 | { |
| 8267 | struct nfs4_layoutcommit_data *data = calldata; |
| 8268 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8269 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8270 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8271 | return; |
| 8272 | |
| 8273 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8274 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8275 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8276 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8277 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8278 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8279 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8280 | break; |
| 8281 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8282 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8283 | rpc_restart_call_prepare(task); |
| 8284 | return; |
| 8285 | } |
| 8286 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8287 | } |
| 8288 | |
| 8289 | static void nfs4_layoutcommit_release(void *calldata) |
| 8290 | { |
| 8291 | struct nfs4_layoutcommit_data *data = calldata; |
| 8292 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8293 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8294 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8295 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8296 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8297 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8298 | kfree(data); |
| 8299 | } |
| 8300 | |
| 8301 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8302 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8303 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8304 | .rpc_release = nfs4_layoutcommit_release, |
| 8305 | }; |
| 8306 | |
| 8307 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8308 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8309 | { |
| 8310 | struct rpc_message msg = { |
| 8311 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8312 | .rpc_argp = &data->args, |
| 8313 | .rpc_resp = &data->res, |
| 8314 | .rpc_cred = data->cred, |
| 8315 | }; |
| 8316 | struct rpc_task_setup task_setup_data = { |
| 8317 | .task = &data->task, |
| 8318 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8319 | .rpc_message = &msg, |
| 8320 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8321 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8322 | }; |
| 8323 | struct rpc_task *task; |
| 8324 | int status = 0; |
| 8325 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8326 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8327 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8328 | data->args.lastbytewritten, |
| 8329 | data->args.inode->i_ino); |
| 8330 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8331 | if (!sync) { |
| 8332 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8333 | if (data->inode == NULL) { |
| 8334 | nfs4_layoutcommit_release(data); |
| 8335 | return -EAGAIN; |
| 8336 | } |
| 8337 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8338 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8339 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8340 | task = rpc_run_task(&task_setup_data); |
| 8341 | if (IS_ERR(task)) |
| 8342 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8343 | if (sync) |
| 8344 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8345 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8346 | dprintk("%s: status %d\n", __func__, status); |
| 8347 | rpc_put_task(task); |
| 8348 | return status; |
| 8349 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8350 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8351 | /** |
| 8352 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8353 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8354 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8355 | static int |
| 8356 | _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] | 8357 | struct nfs_fsinfo *info, |
| 8358 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8359 | { |
| 8360 | struct nfs41_secinfo_no_name_args args = { |
| 8361 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8362 | }; |
| 8363 | struct nfs4_secinfo_res res = { |
| 8364 | .flavors = flavors, |
| 8365 | }; |
| 8366 | struct rpc_message msg = { |
| 8367 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8368 | .rpc_argp = &args, |
| 8369 | .rpc_resp = &res, |
| 8370 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8371 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8372 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8373 | int status; |
| 8374 | |
| 8375 | if (use_integrity) { |
| 8376 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8377 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8378 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | dprintk("--> %s\n", __func__); |
| 8382 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8383 | &res.seq_res, 0); |
| 8384 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8385 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8386 | if (cred) |
| 8387 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8388 | |
| 8389 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8390 | } |
| 8391 | |
| 8392 | static int |
| 8393 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8394 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8395 | { |
| 8396 | struct nfs4_exception exception = { }; |
| 8397 | int err; |
| 8398 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8399 | /* first try using integrity protection */ |
| 8400 | err = -NFS4ERR_WRONGSEC; |
| 8401 | |
| 8402 | /* try to use integrity protection with machine cred */ |
| 8403 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8404 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8405 | flavors, true); |
| 8406 | |
| 8407 | /* |
| 8408 | * if unable to use integrity protection, or SECINFO with |
| 8409 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8410 | * disallowed by spec, but exists in deployed servers) use |
| 8411 | * the current filesystem's rpc_client and the user cred. |
| 8412 | */ |
| 8413 | if (err == -NFS4ERR_WRONGSEC) |
| 8414 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8415 | flavors, false); |
| 8416 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8417 | switch (err) { |
| 8418 | case 0: |
| 8419 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8420 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8421 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8422 | default: |
| 8423 | err = nfs4_handle_exception(server, err, &exception); |
| 8424 | } |
| 8425 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8426 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8427 | return err; |
| 8428 | } |
| 8429 | |
| 8430 | static int |
| 8431 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8432 | struct nfs_fsinfo *info) |
| 8433 | { |
| 8434 | int err; |
| 8435 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8436 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8437 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8438 | struct nfs4_secinfo4 *secinfo; |
| 8439 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8440 | |
| 8441 | page = alloc_page(GFP_KERNEL); |
| 8442 | if (!page) { |
| 8443 | err = -ENOMEM; |
| 8444 | goto out; |
| 8445 | } |
| 8446 | |
| 8447 | flavors = page_address(page); |
| 8448 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8449 | |
| 8450 | /* |
| 8451 | * Fall back on "guess and check" method if |
| 8452 | * the server doesn't support SECINFO_NO_NAME |
| 8453 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8454 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8455 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8456 | goto out_freepage; |
| 8457 | } |
| 8458 | if (err) |
| 8459 | goto out_freepage; |
| 8460 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8461 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8462 | secinfo = &flavors->flavors[i]; |
| 8463 | |
| 8464 | switch (secinfo->flavor) { |
| 8465 | case RPC_AUTH_NULL: |
| 8466 | case RPC_AUTH_UNIX: |
| 8467 | case RPC_AUTH_GSS: |
| 8468 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8469 | &secinfo->flavor_info); |
| 8470 | break; |
| 8471 | default: |
| 8472 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8473 | break; |
| 8474 | } |
| 8475 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8476 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8477 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8478 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8479 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8480 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8481 | info, flavor); |
| 8482 | if (!err) |
| 8483 | break; |
| 8484 | } |
| 8485 | } |
| 8486 | |
| 8487 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8488 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8489 | |
| 8490 | out_freepage: |
| 8491 | put_page(page); |
| 8492 | if (err == -EACCES) |
| 8493 | return -EPERM; |
| 8494 | out: |
| 8495 | return err; |
| 8496 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8497 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8498 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8499 | nfs4_stateid *stateid, |
| 8500 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8501 | { |
| 8502 | int status; |
| 8503 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8504 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8505 | }; |
| 8506 | struct nfs41_test_stateid_res res; |
| 8507 | struct rpc_message msg = { |
| 8508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8509 | .rpc_argp = &args, |
| 8510 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8511 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8512 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8513 | struct rpc_clnt *rpc_client = server->client; |
| 8514 | |
| 8515 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8516 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8517 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8518 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8519 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8520 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8521 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8522 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8523 | if (status != NFS_OK) { |
| 8524 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8525 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8526 | } |
| 8527 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8528 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8529 | } |
| 8530 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8531 | /** |
| 8532 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8533 | * |
| 8534 | * @server: server / transport on which to perform the operation |
| 8535 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8536 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8537 | * |
| 8538 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8539 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8540 | * failed or the state ID is not currently valid. |
| 8541 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8542 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8543 | nfs4_stateid *stateid, |
| 8544 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8545 | { |
| 8546 | struct nfs4_exception exception = { }; |
| 8547 | int err; |
| 8548 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8549 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8550 | if (err != -NFS4ERR_DELAY) |
| 8551 | break; |
| 8552 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8553 | } while (exception.retry); |
| 8554 | return err; |
| 8555 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8556 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8557 | struct nfs_free_stateid_data { |
| 8558 | struct nfs_server *server; |
| 8559 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8560 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8561 | }; |
| 8562 | |
| 8563 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8564 | { |
| 8565 | struct nfs_free_stateid_data *data = calldata; |
| 8566 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8567 | &data->args.seq_args, |
| 8568 | &data->res.seq_res, |
| 8569 | task); |
| 8570 | } |
| 8571 | |
| 8572 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8573 | { |
| 8574 | struct nfs_free_stateid_data *data = calldata; |
| 8575 | |
| 8576 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8577 | |
| 8578 | switch (task->tk_status) { |
| 8579 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8580 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8581 | rpc_restart_call_prepare(task); |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | static void nfs41_free_stateid_release(void *calldata) |
| 8586 | { |
| 8587 | kfree(calldata); |
| 8588 | } |
| 8589 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8590 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8591 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8592 | .rpc_call_done = nfs41_free_stateid_done, |
| 8593 | .rpc_release = nfs41_free_stateid_release, |
| 8594 | }; |
| 8595 | |
| 8596 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8597 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8598 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8599 | bool privileged) |
| 8600 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8601 | struct rpc_message msg = { |
| 8602 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8603 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8604 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8605 | struct rpc_task_setup task_setup = { |
| 8606 | .rpc_client = server->client, |
| 8607 | .rpc_message = &msg, |
| 8608 | .callback_ops = &nfs41_free_stateid_ops, |
| 8609 | .flags = RPC_TASK_ASYNC, |
| 8610 | }; |
| 8611 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8612 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8613 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8614 | &task_setup.rpc_client, &msg); |
| 8615 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8616 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8617 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8618 | if (!data) |
| 8619 | return ERR_PTR(-ENOMEM); |
| 8620 | data->server = server; |
| 8621 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8622 | |
| 8623 | task_setup.callback_data = data; |
| 8624 | |
| 8625 | msg.rpc_argp = &data->args; |
| 8626 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8627 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8628 | if (privileged) |
| 8629 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8630 | |
| 8631 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8632 | } |
| 8633 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8634 | /** |
| 8635 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8636 | * |
| 8637 | * @server: server / transport on which to perform the operation |
| 8638 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8639 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8640 | * |
| 8641 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8642 | * negative NFS4ERR value is returned. |
| 8643 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8644 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8645 | nfs4_stateid *stateid, |
| 8646 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8647 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8648 | struct rpc_task *task; |
| 8649 | int ret; |
| 8650 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8651 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8652 | if (IS_ERR(task)) |
| 8653 | return PTR_ERR(task); |
| 8654 | ret = rpc_wait_for_completion_task(task); |
| 8655 | if (!ret) |
| 8656 | ret = task->tk_status; |
| 8657 | rpc_put_task(task); |
| 8658 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8659 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8660 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8661 | static void |
| 8662 | 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] | 8663 | { |
| 8664 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8665 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8666 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8667 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8668 | nfs4_free_lock_state(server, lsp); |
| 8669 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8670 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8671 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8672 | } |
| 8673 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8674 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8675 | const nfs4_stateid *s2) |
| 8676 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8677 | if (s1->type != s2->type) |
| 8678 | return false; |
| 8679 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8680 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8681 | return false; |
| 8682 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8683 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8684 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8685 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8686 | return true; |
| 8687 | |
| 8688 | return false; |
| 8689 | } |
| 8690 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8691 | #endif /* CONFIG_NFS_V4_1 */ |
| 8692 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8693 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8694 | const nfs4_stateid *s2) |
| 8695 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8696 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8697 | } |
| 8698 | |
| 8699 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8700 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8701 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8702 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8703 | .recover_open = nfs4_open_reclaim, |
| 8704 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8705 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8706 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8707 | }; |
| 8708 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8709 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8710 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8711 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8712 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8713 | .recover_open = nfs4_open_reclaim, |
| 8714 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8715 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8716 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8717 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8718 | }; |
| 8719 | #endif /* CONFIG_NFS_V4_1 */ |
| 8720 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8721 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8722 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8723 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8724 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8725 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8726 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8727 | }; |
| 8728 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8729 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8730 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8731 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8732 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8733 | .recover_open = nfs41_open_expired, |
| 8734 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8735 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8736 | }; |
| 8737 | #endif /* CONFIG_NFS_V4_1 */ |
| 8738 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8739 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8740 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8741 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8742 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8743 | }; |
| 8744 | |
| 8745 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8746 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8747 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8748 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8749 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8750 | }; |
| 8751 | #endif |
| 8752 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8753 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8754 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8755 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8756 | }; |
| 8757 | |
| 8758 | #if defined(CONFIG_NFS_V4_1) |
| 8759 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8760 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8761 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8762 | }; |
| 8763 | #endif /* CONFIG_NFS_V4_1 */ |
| 8764 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8765 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8766 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8767 | .init_caps = NFS_CAP_READDIRPLUS |
| 8768 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8769 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8770 | .init_client = nfs40_init_client, |
| 8771 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8772 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8773 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8774 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8775 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8776 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8777 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8778 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8779 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8780 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8781 | }; |
| 8782 | |
| 8783 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8784 | static struct nfs_seqid * |
| 8785 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 8786 | { |
| 8787 | return NULL; |
| 8788 | } |
| 8789 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8790 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8791 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8792 | .init_caps = NFS_CAP_READDIRPLUS |
| 8793 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8794 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8795 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8796 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8797 | .init_client = nfs41_init_client, |
| 8798 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8799 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8800 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8801 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8802 | .alloc_seqid = nfs_alloc_no_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8803 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8804 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8805 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8806 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8807 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8808 | }; |
| 8809 | #endif |
| 8810 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8811 | #if defined(CONFIG_NFS_V4_2) |
| 8812 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8813 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8814 | .init_caps = NFS_CAP_READDIRPLUS |
| 8815 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8816 | | NFS_CAP_POSIX_LOCK |
| 8817 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8818 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8819 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 8820 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8821 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 8822 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 8823 | | NFS_CAP_LAYOUTSTATS |
| 8824 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8825 | .init_client = nfs41_init_client, |
| 8826 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8827 | .match_stateid = nfs41_match_stateid, |
| 8828 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8829 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8830 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8831 | .alloc_seqid = nfs_alloc_no_seqid, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8832 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8833 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8834 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 8835 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8836 | }; |
| 8837 | #endif |
| 8838 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8839 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8840 | [0] = &nfs_v4_0_minor_ops, |
| 8841 | #if defined(CONFIG_NFS_V4_1) |
| 8842 | [1] = &nfs_v4_1_minor_ops, |
| 8843 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8844 | #if defined(CONFIG_NFS_V4_2) |
| 8845 | [2] = &nfs_v4_2_minor_ops, |
| 8846 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8847 | }; |
| 8848 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 8849 | 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] | 8850 | { |
| 8851 | ssize_t error, error2; |
| 8852 | |
| 8853 | error = generic_listxattr(dentry, list, size); |
| 8854 | if (error < 0) |
| 8855 | return error; |
| 8856 | if (list) { |
| 8857 | list += error; |
| 8858 | size -= error; |
| 8859 | } |
| 8860 | |
| 8861 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 8862 | if (error2 < 0) |
| 8863 | return error2; |
| 8864 | return error + error2; |
| 8865 | } |
| 8866 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8867 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8868 | .create = nfs_create, |
| 8869 | .lookup = nfs_lookup, |
| 8870 | .atomic_open = nfs_atomic_open, |
| 8871 | .link = nfs_link, |
| 8872 | .unlink = nfs_unlink, |
| 8873 | .symlink = nfs_symlink, |
| 8874 | .mkdir = nfs_mkdir, |
| 8875 | .rmdir = nfs_rmdir, |
| 8876 | .mknod = nfs_mknod, |
| 8877 | .rename = nfs_rename, |
| 8878 | .permission = nfs_permission, |
| 8879 | .getattr = nfs_getattr, |
| 8880 | .setattr = nfs_setattr, |
| 8881 | .getxattr = generic_getxattr, |
| 8882 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 8883 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8884 | .removexattr = generic_removexattr, |
| 8885 | }; |
| 8886 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8887 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8888 | .permission = nfs_permission, |
| 8889 | .getattr = nfs_getattr, |
| 8890 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8891 | .getxattr = generic_getxattr, |
| 8892 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 8893 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8894 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8895 | }; |
| 8896 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8897 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8898 | .version = 4, /* protocol version */ |
| 8899 | .dentry_ops = &nfs4_dentry_operations, |
| 8900 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8901 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8902 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8903 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8904 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8905 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8906 | .getattr = nfs4_proc_getattr, |
| 8907 | .setattr = nfs4_proc_setattr, |
| 8908 | .lookup = nfs4_proc_lookup, |
| 8909 | .access = nfs4_proc_access, |
| 8910 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8911 | .create = nfs4_proc_create, |
| 8912 | .remove = nfs4_proc_remove, |
| 8913 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8914 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8915 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8916 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8917 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8918 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8919 | .link = nfs4_proc_link, |
| 8920 | .symlink = nfs4_proc_symlink, |
| 8921 | .mkdir = nfs4_proc_mkdir, |
| 8922 | .rmdir = nfs4_proc_remove, |
| 8923 | .readdir = nfs4_proc_readdir, |
| 8924 | .mknod = nfs4_proc_mknod, |
| 8925 | .statfs = nfs4_proc_statfs, |
| 8926 | .fsinfo = nfs4_proc_fsinfo, |
| 8927 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8928 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8929 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8930 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8931 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8932 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8933 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8934 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8935 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8936 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8937 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8938 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8939 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8940 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8941 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8942 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8943 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8944 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8945 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8946 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8947 | .create_server = nfs4_create_server, |
| 8948 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8949 | }; |
| 8950 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8951 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 8952 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8953 | .list = nfs4_xattr_list_nfs4_acl, |
| 8954 | .get = nfs4_xattr_get_nfs4_acl, |
| 8955 | .set = nfs4_xattr_set_nfs4_acl, |
| 8956 | }; |
| 8957 | |
| 8958 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8959 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8960 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8961 | &nfs4_xattr_nfs4_label_handler, |
| 8962 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8963 | NULL |
| 8964 | }; |
| 8965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8966 | /* |
| 8967 | * Local variables: |
| 8968 | * c-basic-offset: 8 |
| 8969 | * End: |
| 8970 | */ |