Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 100 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 101 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 102 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 103 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 229 | | FATTR4_WORD0_CHANGE |
| 230 | | FATTR4_WORD0_FILEID, |
| 231 | }; |
| 232 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 233 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | FATTR4_WORD0_FILES_AVAIL |
| 235 | | FATTR4_WORD0_FILES_FREE |
| 236 | | FATTR4_WORD0_FILES_TOTAL, |
| 237 | FATTR4_WORD1_SPACE_AVAIL |
| 238 | | FATTR4_WORD1_SPACE_FREE |
| 239 | | FATTR4_WORD1_SPACE_TOTAL |
| 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | FATTR4_WORD0_MAXLINK |
| 244 | | FATTR4_WORD0_MAXNAME, |
| 245 | 0 |
| 246 | }; |
| 247 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 248 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | | FATTR4_WORD0_MAXREAD |
| 250 | | FATTR4_WORD0_MAXWRITE |
| 251 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 252 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 253 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 254 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 255 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | FATTR4_WORD0_TYPE |
| 260 | | FATTR4_WORD0_CHANGE |
| 261 | | FATTR4_WORD0_SIZE |
| 262 | | FATTR4_WORD0_FSID |
| 263 | | FATTR4_WORD0_FILEID |
| 264 | | FATTR4_WORD0_FS_LOCATIONS, |
| 265 | FATTR4_WORD1_MODE |
| 266 | | FATTR4_WORD1_NUMLINKS |
| 267 | | FATTR4_WORD1_OWNER |
| 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | readdir->cookie = 0; |
| 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 290 | if (cookie == 2) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * NFSv4 servers do not return entries for '.' and '..' |
| 295 | * Therefore, we fake these entries here. We let '.' |
| 296 | * have cookie 0 and '..' have cookie 1. Note that |
| 297 | * when talking to the server, we always send cookie 0 |
| 298 | * instead of 1 or 2. |
| 299 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (cookie == 0) { |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_one; /* cookie, second word */ |
| 306 | *p++ = xdr_one; /* entry len */ |
| 307 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
| 322 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 323 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 324 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | readdir->pgbase = (char *)p - (char *)start; |
| 327 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 331 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 332 | nfs4_stateid *stateid, |
| 333 | struct rpc_cred *cred) |
| 334 | { |
| 335 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 336 | |
| 337 | ops->test_and_free_expired(server, stateid, cred); |
| 338 | } |
| 339 | |
| 340 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 341 | nfs4_stateid *stateid, |
| 342 | struct rpc_cred *cred) |
| 343 | { |
| 344 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 345 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 346 | } |
| 347 | |
| 348 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 349 | const nfs4_stateid *stateid, |
| 350 | struct rpc_cred *cred) |
| 351 | { |
| 352 | nfs4_stateid tmp; |
| 353 | |
| 354 | nfs4_stateid_copy(&tmp, stateid); |
| 355 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 356 | } |
| 357 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 358 | static long nfs4_update_delay(long *timeout) |
| 359 | { |
| 360 | long ret; |
| 361 | if (!timeout) |
| 362 | return NFS4_POLL_RETRY_MAX; |
| 363 | if (*timeout <= 0) |
| 364 | *timeout = NFS4_POLL_RETRY_MIN; |
| 365 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 366 | *timeout = NFS4_POLL_RETRY_MAX; |
| 367 | ret = *timeout; |
| 368 | *timeout <<= 1; |
| 369 | return ret; |
| 370 | } |
| 371 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 373 | { |
| 374 | int res = 0; |
| 375 | |
| 376 | might_sleep(); |
| 377 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 378 | freezable_schedule_timeout_killable_unsafe( |
| 379 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | if (fatal_signal_pending(current)) |
| 381 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | return res; |
| 383 | } |
| 384 | |
| 385 | /* This is the error handling routine for processes that are allowed |
| 386 | * to sleep. |
| 387 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 388 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 389 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 390 | { |
| 391 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 392 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 393 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 394 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 395 | int ret = errorcode; |
| 396 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 397 | exception->delay = 0; |
| 398 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 400 | |
| 401 | if (stateid == NULL && state != NULL) |
| 402 | stateid = &state->stateid; |
| 403 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | switch(errorcode) { |
| 405 | case 0: |
| 406 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 407 | case -NFS4ERR_DELEG_REVOKED: |
| 408 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 409 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 410 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 411 | if (inode != NULL && stateid != NULL) { |
| 412 | nfs_inode_find_state_and_recover(inode, |
| 413 | stateid); |
| 414 | goto wait_on_recovery; |
| 415 | } |
| 416 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 417 | if (inode) { |
| 418 | int err; |
| 419 | |
| 420 | err = nfs_async_inode_return_delegation(inode, |
| 421 | stateid); |
| 422 | if (err == 0) |
| 423 | goto wait_on_recovery; |
| 424 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 425 | exception->retry = 1; |
| 426 | break; |
| 427 | } |
| 428 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 429 | if (state == NULL) |
| 430 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 431 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 432 | if (ret < 0) |
| 433 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 434 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 436 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 437 | nfs4_schedule_lease_recovery(clp); |
| 438 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 439 | case -NFS4ERR_MOVED: |
| 440 | ret = nfs4_schedule_migration_recovery(server); |
| 441 | if (ret < 0) |
| 442 | break; |
| 443 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 444 | case -NFS4ERR_LEASE_MOVED: |
| 445 | nfs4_schedule_lease_moved_recovery(clp); |
| 446 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 447 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 448 | case -NFS4ERR_BADSESSION: |
| 449 | case -NFS4ERR_BADSLOT: |
| 450 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 451 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 452 | case -NFS4ERR_DEADSESSION: |
| 453 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 454 | case -NFS4ERR_SEQ_MISORDERED: |
| 455 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 456 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 457 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 458 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 459 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 460 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 461 | if (exception->timeout > HZ) { |
| 462 | /* We have retried a decent amount, time to |
| 463 | * fail |
| 464 | */ |
| 465 | ret = -EBUSY; |
| 466 | break; |
| 467 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 468 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 469 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 470 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 471 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 472 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 473 | exception->delay = 1; |
| 474 | return 0; |
| 475 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 476 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 477 | case -NFS4ERR_OLD_STATEID: |
| 478 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 479 | break; |
| 480 | case -NFS4ERR_BADOWNER: |
| 481 | /* The following works around a Linux server bug! */ |
| 482 | case -NFS4ERR_BADNAME: |
| 483 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 484 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 485 | exception->retry = 1; |
| 486 | printk(KERN_WARNING "NFS: v4 server %s " |
| 487 | "does not accept raw " |
| 488 | "uid/gids. " |
| 489 | "Reenabling the idmapper.\n", |
| 490 | server->nfs_client->cl_hostname); |
| 491 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 492 | } |
| 493 | /* We failed to handle the error */ |
| 494 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 495 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 496 | exception->recovering = 1; |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /* This is the error handling routine for processes that are allowed |
| 501 | * to sleep. |
| 502 | */ |
| 503 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 504 | { |
| 505 | struct nfs_client *clp = server->nfs_client; |
| 506 | int ret; |
| 507 | |
| 508 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 509 | if (exception->delay) { |
| 510 | ret = nfs4_delay(server->client, &exception->timeout); |
| 511 | goto out_retry; |
| 512 | } |
| 513 | if (exception->recovering) { |
| 514 | ret = nfs4_wait_clnt_recover(clp); |
| 515 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 516 | return -EIO; |
| 517 | goto out_retry; |
| 518 | } |
| 519 | return ret; |
| 520 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 521 | if (ret == 0) |
| 522 | exception->retry = 1; |
| 523 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 526 | static int |
| 527 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 528 | int errorcode, struct nfs4_exception *exception) |
| 529 | { |
| 530 | struct nfs_client *clp = server->nfs_client; |
| 531 | int ret; |
| 532 | |
| 533 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 534 | if (exception->delay) { |
| 535 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 536 | goto out_retry; |
| 537 | } |
| 538 | if (exception->recovering) { |
| 539 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 540 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 541 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 542 | goto out_retry; |
| 543 | } |
| 544 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 545 | ret = -EIO; |
| 546 | return ret; |
| 547 | out_retry: |
| 548 | if (ret == 0) |
| 549 | exception->retry = 1; |
| 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | static int |
| 554 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 555 | struct nfs4_state *state, long *timeout) |
| 556 | { |
| 557 | struct nfs4_exception exception = { |
| 558 | .state = state, |
| 559 | }; |
| 560 | |
| 561 | if (task->tk_status >= 0) |
| 562 | return 0; |
| 563 | if (timeout) |
| 564 | exception.timeout = *timeout; |
| 565 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 566 | task->tk_status, |
| 567 | &exception); |
| 568 | if (exception.delay && timeout) |
| 569 | *timeout = exception.timeout; |
| 570 | if (exception.retry) |
| 571 | return -EAGAIN; |
| 572 | return 0; |
| 573 | } |
| 574 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 575 | /* |
| 576 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 577 | * or 'false' otherwise. |
| 578 | */ |
| 579 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 580 | { |
| 581 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 582 | |
| 583 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 584 | flavor == RPC_AUTH_GSS_KRB5P) |
| 585 | return true; |
| 586 | |
| 587 | return false; |
| 588 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 589 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 590 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | spin_lock(&clp->cl_lock); |
| 593 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 594 | clp->cl_last_renewal = timestamp; |
| 595 | spin_unlock(&clp->cl_lock); |
| 596 | } |
| 597 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 598 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 599 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 600 | struct nfs_client *clp = server->nfs_client; |
| 601 | |
| 602 | if (!nfs4_has_session(clp)) |
| 603 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 606 | struct nfs4_call_sync_data { |
| 607 | const struct nfs_server *seq_server; |
| 608 | struct nfs4_sequence_args *seq_args; |
| 609 | struct nfs4_sequence_res *seq_res; |
| 610 | }; |
| 611 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 612 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 613 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 614 | { |
| 615 | args->sa_slot = NULL; |
| 616 | args->sa_cache_this = cache_reply; |
| 617 | args->sa_privileged = 0; |
| 618 | |
| 619 | res->sr_slot = NULL; |
| 620 | } |
| 621 | |
| 622 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 623 | { |
| 624 | args->sa_privileged = 1; |
| 625 | } |
| 626 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 627 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 628 | struct nfs4_sequence_args *args, |
| 629 | struct nfs4_sequence_res *res, |
| 630 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 631 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 632 | struct nfs4_slot *slot; |
| 633 | |
| 634 | /* slot already allocated? */ |
| 635 | if (res->sr_slot != NULL) |
| 636 | goto out_start; |
| 637 | |
| 638 | spin_lock(&tbl->slot_tbl_lock); |
| 639 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 640 | goto out_sleep; |
| 641 | |
| 642 | slot = nfs4_alloc_slot(tbl); |
| 643 | if (IS_ERR(slot)) { |
| 644 | if (slot == ERR_PTR(-ENOMEM)) |
| 645 | task->tk_timeout = HZ >> 2; |
| 646 | goto out_sleep; |
| 647 | } |
| 648 | spin_unlock(&tbl->slot_tbl_lock); |
| 649 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 650 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 651 | args->sa_slot = slot; |
| 652 | res->sr_slot = slot; |
| 653 | |
| 654 | out_start: |
| 655 | rpc_call_start(task); |
| 656 | return 0; |
| 657 | |
| 658 | out_sleep: |
| 659 | if (args->sa_privileged) |
| 660 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 661 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 662 | else |
| 663 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 664 | spin_unlock(&tbl->slot_tbl_lock); |
| 665 | return -EAGAIN; |
| 666 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 667 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 668 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 669 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 670 | { |
| 671 | struct nfs4_slot *slot = res->sr_slot; |
| 672 | struct nfs4_slot_table *tbl; |
| 673 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 674 | tbl = slot->table; |
| 675 | spin_lock(&tbl->slot_tbl_lock); |
| 676 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 677 | nfs4_free_slot(tbl, slot); |
| 678 | spin_unlock(&tbl->slot_tbl_lock); |
| 679 | |
| 680 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static int nfs40_sequence_done(struct rpc_task *task, |
| 684 | struct nfs4_sequence_res *res) |
| 685 | { |
| 686 | if (res->sr_slot != NULL) |
| 687 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 688 | return 1; |
| 689 | } |
| 690 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 691 | #if defined(CONFIG_NFS_V4_1) |
| 692 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 693 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 694 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 695 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 696 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 697 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 698 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 699 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 700 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 701 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 702 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 703 | /* Bump the slot sequence number */ |
| 704 | if (slot->seq_done) |
| 705 | slot->seq_nr++; |
| 706 | slot->seq_done = 0; |
| 707 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 708 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 709 | /* Be nice to the server: try to ensure that the last transmitted |
| 710 | * value for highest_user_slotid <= target_highest_slotid |
| 711 | */ |
| 712 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 713 | send_new_highest_used_slotid = true; |
| 714 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 715 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 716 | send_new_highest_used_slotid = false; |
| 717 | goto out_unlock; |
| 718 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 719 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 720 | |
| 721 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 722 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 723 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 724 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 725 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 726 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 727 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 728 | if (waitqueue_active(&tbl->slot_waitq)) |
| 729 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 732 | static int nfs41_sequence_process(struct rpc_task *task, |
| 733 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 734 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 735 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 736 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 737 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 738 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 739 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 740 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 741 | if (slot == NULL) |
| 742 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 743 | /* don't increment the sequence number if the task wasn't sent */ |
| 744 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 745 | goto out; |
| 746 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 747 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 748 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 749 | if (slot->interrupted) { |
| 750 | slot->interrupted = 0; |
| 751 | interrupted = true; |
| 752 | } |
| 753 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 754 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 755 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 756 | switch (res->sr_status) { |
| 757 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 758 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 759 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 760 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 761 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 762 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 763 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 764 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 765 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 766 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 767 | case 1: |
| 768 | /* |
| 769 | * sr_status remains 1 if an RPC level error occurred. |
| 770 | * The server may or may not have processed the sequence |
| 771 | * operation.. |
| 772 | * Mark the slot as having hosted an interrupted RPC call. |
| 773 | */ |
| 774 | slot->interrupted = 1; |
| 775 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 776 | case -NFS4ERR_DELAY: |
| 777 | /* The server detected a resend of the RPC call and |
| 778 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 779 | * of RFC5661. |
| 780 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 781 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 782 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 783 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 784 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 785 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 786 | case -NFS4ERR_BADSLOT: |
| 787 | /* |
| 788 | * The slot id we used was probably retired. Try again |
| 789 | * using a different slot id. |
| 790 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | goto retry_nowait; |
| 792 | case -NFS4ERR_SEQ_MISORDERED: |
| 793 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 794 | * Was the last operation on this sequence interrupted? |
| 795 | * If so, retry after bumping the sequence number. |
| 796 | */ |
| 797 | if (interrupted) { |
| 798 | ++slot->seq_nr; |
| 799 | goto retry_nowait; |
| 800 | } |
| 801 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 802 | * Could this slot have been previously retired? |
| 803 | * If so, then the server may be expecting seq_nr = 1! |
| 804 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 805 | if (slot->seq_nr != 1) { |
| 806 | slot->seq_nr = 1; |
| 807 | goto retry_nowait; |
| 808 | } |
| 809 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 810 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 811 | ++slot->seq_nr; |
| 812 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 813 | default: |
| 814 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 815 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 816 | } |
| 817 | out: |
| 818 | /* The session may be reset by one of the error handlers. */ |
| 819 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 820 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 821 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 822 | retry_nowait: |
| 823 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 824 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 825 | task->tk_status = 0; |
| 826 | ret = 0; |
| 827 | } |
| 828 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 830 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | goto out; |
| 832 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 833 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 834 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 835 | |
| 836 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 837 | { |
| 838 | if (!nfs41_sequence_process(task, res)) |
| 839 | return 0; |
| 840 | if (res->sr_slot != NULL) |
| 841 | nfs41_sequence_free_slot(res); |
| 842 | return 1; |
| 843 | |
| 844 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 845 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 846 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 847 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 848 | { |
| 849 | if (res->sr_slot == NULL) |
| 850 | return 1; |
| 851 | if (res->sr_slot->table->session != NULL) |
| 852 | return nfs41_sequence_process(task, res); |
| 853 | return nfs40_sequence_done(task, res); |
| 854 | } |
| 855 | |
| 856 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 857 | { |
| 858 | if (res->sr_slot != NULL) { |
| 859 | if (res->sr_slot->table->session != NULL) |
| 860 | nfs41_sequence_free_slot(res); |
| 861 | else |
| 862 | nfs40_sequence_free_slot(res); |
| 863 | } |
| 864 | } |
| 865 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 866 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 867 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 868 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 869 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 870 | if (!res->sr_slot->table->session) |
| 871 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 872 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 873 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 874 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 875 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 876 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | struct nfs4_sequence_args *args, |
| 878 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 879 | struct rpc_task *task) |
| 880 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 881 | struct nfs4_slot *slot; |
| 882 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 883 | |
| 884 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 885 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 886 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 887 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 888 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | tbl = &session->fc_slot_table; |
| 890 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 891 | task->tk_timeout = 0; |
| 892 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 893 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 894 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 895 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 896 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 897 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 898 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 899 | } |
| 900 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 901 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 902 | if (IS_ERR(slot)) { |
| 903 | /* If out of memory, try again in 1/4 second */ |
| 904 | if (slot == ERR_PTR(-ENOMEM)) |
| 905 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 906 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 907 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 908 | } |
| 909 | spin_unlock(&tbl->slot_tbl_lock); |
| 910 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 911 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 912 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 913 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 914 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 915 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 916 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 917 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 918 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 919 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 920 | /* |
| 921 | * sr_status is only set in decode_sequence, and so will remain |
| 922 | * set to 1 if an rpc level failure occurs. |
| 923 | */ |
| 924 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 925 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 926 | out_success: |
| 927 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 928 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 929 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 930 | /* Privileged tasks are queued with top priority */ |
| 931 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 932 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 933 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 934 | else |
| 935 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 936 | spin_unlock(&tbl->slot_tbl_lock); |
| 937 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 938 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 939 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 941 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 942 | struct nfs4_sequence_args *args, |
| 943 | struct nfs4_sequence_res *res, |
| 944 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 945 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 946 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 947 | int ret = 0; |
| 948 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 949 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 950 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 951 | args, res, task); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 952 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 953 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 954 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 955 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 956 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 957 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 958 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 959 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 960 | return ret; |
| 961 | } |
| 962 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 963 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 964 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 965 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 966 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 967 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 968 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 969 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 970 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 971 | } |
| 972 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 973 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 974 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 975 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 976 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 977 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 978 | } |
| 979 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 980 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 981 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 983 | }; |
| 984 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 985 | #else /* !CONFIG_NFS_V4_1 */ |
| 986 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 987 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 988 | struct nfs4_sequence_args *args, |
| 989 | struct nfs4_sequence_res *res, |
| 990 | struct rpc_task *task) |
| 991 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 992 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 993 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 994 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 995 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 996 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 997 | { |
| 998 | return nfs40_sequence_done(task, res); |
| 999 | } |
| 1000 | |
| 1001 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1002 | { |
| 1003 | if (res->sr_slot != NULL) |
| 1004 | nfs40_sequence_free_slot(res); |
| 1005 | } |
| 1006 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1007 | int nfs4_sequence_done(struct rpc_task *task, |
| 1008 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1009 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1010 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1011 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1012 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1013 | |
| 1014 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1015 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1016 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1017 | { |
| 1018 | struct nfs4_call_sync_data *data = calldata; |
| 1019 | nfs4_setup_sequence(data->seq_server, |
| 1020 | data->seq_args, data->seq_res, task); |
| 1021 | } |
| 1022 | |
| 1023 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1024 | { |
| 1025 | struct nfs4_call_sync_data *data = calldata; |
| 1026 | nfs4_sequence_done(task, data->seq_res); |
| 1027 | } |
| 1028 | |
| 1029 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1030 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1031 | .rpc_call_done = nfs40_call_sync_done, |
| 1032 | }; |
| 1033 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1034 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1035 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1039 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1040 | int ret; |
| 1041 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1042 | struct nfs_client *clp = server->nfs_client; |
| 1043 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1044 | .seq_server = server, |
| 1045 | .seq_args = args, |
| 1046 | .seq_res = res, |
| 1047 | }; |
| 1048 | struct rpc_task_setup task_setup = { |
| 1049 | .rpc_client = clnt, |
| 1050 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1051 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | .callback_data = &data |
| 1053 | }; |
| 1054 | |
| 1055 | task = rpc_run_task(&task_setup); |
| 1056 | if (IS_ERR(task)) |
| 1057 | ret = PTR_ERR(task); |
| 1058 | else { |
| 1059 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1060 | rpc_put_task(task); |
| 1061 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1062 | return ret; |
| 1063 | } |
| 1064 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1065 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1066 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1067 | struct rpc_message *msg, |
| 1068 | struct nfs4_sequence_args *args, |
| 1069 | struct nfs4_sequence_res *res, |
| 1070 | int cache_reply) |
| 1071 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1072 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1073 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
| 1076 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1077 | { |
| 1078 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1079 | |
| 1080 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1081 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1082 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1084 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1085 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1086 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | spin_unlock(&dir->i_lock); |
| 1088 | } |
| 1089 | |
| 1090 | struct nfs4_opendata { |
| 1091 | struct kref kref; |
| 1092 | struct nfs_openargs o_arg; |
| 1093 | struct nfs_openres o_res; |
| 1094 | struct nfs_open_confirmargs c_arg; |
| 1095 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1096 | struct nfs4_string owner_name; |
| 1097 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1098 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1100 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1102 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | struct nfs4_state_owner *owner; |
| 1104 | struct nfs4_state *state; |
| 1105 | struct iattr attrs; |
| 1106 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1107 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1108 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1109 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1110 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | int cancelled; |
| 1112 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1113 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1114 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1115 | int err, struct nfs4_exception *exception) |
| 1116 | { |
| 1117 | if (err != -EINVAL) |
| 1118 | return false; |
| 1119 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1120 | return false; |
| 1121 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1122 | exception->retry = 1; |
| 1123 | return true; |
| 1124 | } |
| 1125 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1126 | static u32 |
| 1127 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1128 | fmode_t fmode, int openflags) |
| 1129 | { |
| 1130 | u32 res = 0; |
| 1131 | |
| 1132 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1133 | case FMODE_READ: |
| 1134 | res = NFS4_SHARE_ACCESS_READ; |
| 1135 | break; |
| 1136 | case FMODE_WRITE: |
| 1137 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1138 | break; |
| 1139 | case FMODE_READ|FMODE_WRITE: |
| 1140 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1141 | } |
| 1142 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1143 | goto out; |
| 1144 | /* Want no delegation if we're using O_DIRECT */ |
| 1145 | if (openflags & O_DIRECT) |
| 1146 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1147 | out: |
| 1148 | return res; |
| 1149 | } |
| 1150 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1151 | static enum open_claim_type4 |
| 1152 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1153 | enum open_claim_type4 claim) |
| 1154 | { |
| 1155 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1156 | return claim; |
| 1157 | switch (claim) { |
| 1158 | default: |
| 1159 | return claim; |
| 1160 | case NFS4_OPEN_CLAIM_FH: |
| 1161 | return NFS4_OPEN_CLAIM_NULL; |
| 1162 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1163 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1164 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1165 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1166 | } |
| 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
| 1169 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1170 | { |
| 1171 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1172 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | p->o_res.seqid = p->o_arg.seqid; |
| 1174 | p->c_res.seqid = p->c_arg.seqid; |
| 1175 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1176 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1178 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1181 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1182 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1183 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1184 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1185 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1186 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1188 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1189 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1190 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1191 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1192 | struct nfs4_opendata *p; |
| 1193 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1194 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | if (p == NULL) |
| 1196 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1197 | |
| 1198 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1199 | if (IS_ERR(p->f_label)) |
| 1200 | goto err_free_p; |
| 1201 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1202 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1203 | if (IS_ERR(p->a_label)) |
| 1204 | goto err_free_f; |
| 1205 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1206 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1207 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1208 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1209 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1210 | nfs_sb_active(dentry->d_sb); |
| 1211 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1212 | p->dir = parent; |
| 1213 | p->owner = sp; |
| 1214 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | p->o_arg.open_flags = flags; |
| 1216 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1217 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1218 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1219 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1220 | * will return permission denied for all bits until close */ |
| 1221 | if (!(flags & O_EXCL)) { |
| 1222 | /* ask server to check for all possible rights as results |
| 1223 | * are cached */ |
| 1224 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1225 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1226 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1227 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1228 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1229 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1230 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1231 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1232 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1233 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1234 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1235 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1236 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1237 | case NFS4_OPEN_CLAIM_NULL: |
| 1238 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1239 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1240 | p->o_arg.fh = NFS_FH(dir); |
| 1241 | break; |
| 1242 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1243 | case NFS4_OPEN_CLAIM_FH: |
| 1244 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1245 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1246 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1247 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1248 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1249 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1250 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1251 | p->o_arg.u.attrs = &p->attrs; |
| 1252 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1253 | |
| 1254 | verf[0] = jiffies; |
| 1255 | verf[1] = current->pid; |
| 1256 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1257 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1259 | p->c_arg.fh = &p->o_res.fh; |
| 1260 | p->c_arg.stateid = &p->o_res.stateid; |
| 1261 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1262 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1263 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1264 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1265 | |
| 1266 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1267 | nfs4_label_free(p->a_label); |
| 1268 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1269 | nfs4_label_free(p->f_label); |
| 1270 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | kfree(p); |
| 1272 | err: |
| 1273 | dput(parent); |
| 1274 | return NULL; |
| 1275 | } |
| 1276 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1279 | struct nfs4_opendata *p = container_of(kref, |
| 1280 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1281 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1282 | |
| 1283 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1284 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1285 | if (p->state != NULL) |
| 1286 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1287 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1288 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1289 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1290 | nfs4_label_free(p->f_label); |
| 1291 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1292 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1293 | dput(p->dentry); |
| 1294 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1295 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1296 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1297 | kfree(p); |
| 1298 | } |
| 1299 | |
| 1300 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1301 | { |
| 1302 | if (p != NULL) |
| 1303 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1306 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1307 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1308 | int ret; |
| 1309 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1310 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1311 | return ret; |
| 1312 | } |
| 1313 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1314 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1315 | fmode_t fmode) |
| 1316 | { |
| 1317 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1318 | case FMODE_READ|FMODE_WRITE: |
| 1319 | return state->n_rdwr != 0; |
| 1320 | case FMODE_WRITE: |
| 1321 | return state->n_wronly != 0; |
| 1322 | case FMODE_READ: |
| 1323 | return state->n_rdonly != 0; |
| 1324 | } |
| 1325 | WARN_ON_ONCE(1); |
| 1326 | return false; |
| 1327 | } |
| 1328 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1329 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1330 | { |
| 1331 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1332 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1333 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1334 | goto out; |
| 1335 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1336 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1337 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1338 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1339 | break; |
| 1340 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1341 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1342 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1343 | break; |
| 1344 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1345 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1346 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1347 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1349 | return ret; |
| 1350 | } |
| 1351 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1352 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1353 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1354 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1355 | if (delegation == NULL) |
| 1356 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1358 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1359 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1360 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1361 | switch (claim) { |
| 1362 | case NFS4_OPEN_CLAIM_NULL: |
| 1363 | case NFS4_OPEN_CLAIM_FH: |
| 1364 | break; |
| 1365 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1366 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1367 | break; |
| 1368 | default: |
| 1369 | return 0; |
| 1370 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1371 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1372 | return 1; |
| 1373 | } |
| 1374 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1375 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1376 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1377 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1378 | case FMODE_WRITE: |
| 1379 | state->n_wronly++; |
| 1380 | break; |
| 1381 | case FMODE_READ: |
| 1382 | state->n_rdonly++; |
| 1383 | break; |
| 1384 | case FMODE_READ|FMODE_WRITE: |
| 1385 | state->n_rdwr++; |
| 1386 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1387 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame^] | 1390 | #ifdef CONFIG_NFS_V4_1 |
| 1391 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1392 | { |
| 1393 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1394 | return true; |
| 1395 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1396 | return true; |
| 1397 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1398 | return true; |
| 1399 | return false; |
| 1400 | } |
| 1401 | #endif /* CONFIG_NFS_V4_1 */ |
| 1402 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1403 | 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] | 1404 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1405 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1406 | bool need_recover = false; |
| 1407 | |
| 1408 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1409 | need_recover = true; |
| 1410 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1411 | need_recover = true; |
| 1412 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1413 | need_recover = true; |
| 1414 | if (need_recover) |
| 1415 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1416 | } |
| 1417 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1418 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1419 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1420 | { |
| 1421 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1422 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1423 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1424 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1425 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1426 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1427 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1428 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1429 | return true; |
| 1430 | return false; |
| 1431 | } |
| 1432 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1433 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1434 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1435 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1436 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1437 | if (state->n_wronly) |
| 1438 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1439 | if (state->n_rdonly) |
| 1440 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1441 | if (state->n_rdwr) |
| 1442 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1443 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1444 | } |
| 1445 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1446 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1447 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1448 | nfs4_stateid *stateid, fmode_t fmode) |
| 1449 | { |
| 1450 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1451 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1452 | case FMODE_WRITE: |
| 1453 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1454 | break; |
| 1455 | case FMODE_READ: |
| 1456 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1457 | break; |
| 1458 | case 0: |
| 1459 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1460 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1461 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1462 | } |
| 1463 | if (stateid == NULL) |
| 1464 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1465 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1466 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1467 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1468 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1469 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1470 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1471 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1472 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1473 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1474 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1475 | } |
| 1476 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1477 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1478 | nfs4_stateid *arg_stateid, |
| 1479 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1480 | { |
| 1481 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1482 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1483 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1484 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1485 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1486 | } |
| 1487 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1488 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1489 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1490 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1491 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1492 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1493 | case FMODE_READ: |
| 1494 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1495 | break; |
| 1496 | case FMODE_WRITE: |
| 1497 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1498 | break; |
| 1499 | case FMODE_READ|FMODE_WRITE: |
| 1500 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1501 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1502 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1503 | return; |
| 1504 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1505 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1506 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1509 | static void __update_open_stateid(struct nfs4_state *state, |
| 1510 | const nfs4_stateid *open_stateid, |
| 1511 | const nfs4_stateid *deleg_stateid, |
| 1512 | fmode_t fmode, |
| 1513 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1515 | /* |
| 1516 | * Protect the call to nfs4_state_set_mode_locked and |
| 1517 | * serialise the stateid update |
| 1518 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1519 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1520 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1521 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1522 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1523 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1524 | } |
| 1525 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1526 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1527 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1528 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1529 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1532 | static int update_open_stateid(struct nfs4_state *state, |
| 1533 | const nfs4_stateid *open_stateid, |
| 1534 | const nfs4_stateid *delegation, |
| 1535 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1536 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1537 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1538 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1539 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1540 | struct nfs_delegation *deleg_cur; |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1541 | nfs4_stateid freeme = {0}; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1542 | int ret = 0; |
| 1543 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1544 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1545 | |
| 1546 | rcu_read_lock(); |
| 1547 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1548 | if (deleg_cur == NULL) |
| 1549 | goto no_delegation; |
| 1550 | |
| 1551 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1552 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1553 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1554 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1555 | goto no_delegation_unlock; |
| 1556 | |
| 1557 | if (delegation == NULL) |
| 1558 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1559 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1560 | goto no_delegation_unlock; |
| 1561 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1562 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1563 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1564 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1565 | ret = 1; |
| 1566 | no_delegation_unlock: |
| 1567 | spin_unlock(&deleg_cur->lock); |
| 1568 | no_delegation: |
| 1569 | rcu_read_unlock(); |
| 1570 | |
| 1571 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1572 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1573 | ret = 1; |
| 1574 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1575 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1576 | nfs4_schedule_state_manager(clp); |
| 1577 | if (freeme.type != 0) |
| 1578 | nfs4_test_and_free_stateid(server, &freeme, |
| 1579 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1580 | |
| 1581 | return ret; |
| 1582 | } |
| 1583 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1584 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1585 | const nfs4_stateid *stateid) |
| 1586 | { |
| 1587 | struct nfs4_state *state = lsp->ls_state; |
| 1588 | bool ret = false; |
| 1589 | |
| 1590 | spin_lock(&state->state_lock); |
| 1591 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1592 | goto out_noupdate; |
| 1593 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1594 | goto out_noupdate; |
| 1595 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1596 | ret = true; |
| 1597 | out_noupdate: |
| 1598 | spin_unlock(&state->state_lock); |
| 1599 | return ret; |
| 1600 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1601 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1602 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1603 | { |
| 1604 | struct nfs_delegation *delegation; |
| 1605 | |
| 1606 | rcu_read_lock(); |
| 1607 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1608 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1609 | rcu_read_unlock(); |
| 1610 | return; |
| 1611 | } |
| 1612 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1613 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1614 | } |
| 1615 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1616 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1617 | { |
| 1618 | struct nfs4_state *state = opendata->state; |
| 1619 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1620 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1621 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1622 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1623 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1624 | nfs4_stateid stateid; |
| 1625 | int ret = -EAGAIN; |
| 1626 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1627 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1628 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1629 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1630 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1631 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1632 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1633 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1634 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1635 | rcu_read_lock(); |
| 1636 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1637 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1638 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1639 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1640 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1641 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1642 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1643 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1644 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1645 | if (!opendata->is_recover) { |
| 1646 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1647 | if (ret != 0) |
| 1648 | goto out; |
| 1649 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1650 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1651 | |
| 1652 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1653 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1654 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1655 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1656 | out: |
| 1657 | return ERR_PTR(ret); |
| 1658 | out_return_state: |
| 1659 | atomic_inc(&state->count); |
| 1660 | return state; |
| 1661 | } |
| 1662 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1663 | static void |
| 1664 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1665 | { |
| 1666 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1667 | struct nfs_delegation *delegation; |
| 1668 | int delegation_flags = 0; |
| 1669 | |
| 1670 | rcu_read_lock(); |
| 1671 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1672 | if (delegation) |
| 1673 | delegation_flags = delegation->flags; |
| 1674 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1675 | switch (data->o_arg.claim) { |
| 1676 | default: |
| 1677 | break; |
| 1678 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1679 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1680 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1681 | "returning a delegation for " |
| 1682 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1683 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1684 | return; |
| 1685 | } |
| 1686 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1687 | nfs_inode_set_delegation(state->inode, |
| 1688 | data->owner->so_cred, |
| 1689 | &data->o_res); |
| 1690 | else |
| 1691 | nfs_inode_reclaim_delegation(state->inode, |
| 1692 | data->owner->so_cred, |
| 1693 | &data->o_res); |
| 1694 | } |
| 1695 | |
| 1696 | /* |
| 1697 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1698 | * and update the nfs4_state. |
| 1699 | */ |
| 1700 | static struct nfs4_state * |
| 1701 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1702 | { |
| 1703 | struct inode *inode = data->state->inode; |
| 1704 | struct nfs4_state *state = data->state; |
| 1705 | int ret; |
| 1706 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1707 | if (!data->rpc_done) { |
| 1708 | if (data->rpc_status) { |
| 1709 | ret = data->rpc_status; |
| 1710 | goto err; |
| 1711 | } |
| 1712 | /* cached opens have already been processed */ |
| 1713 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1714 | } |
| 1715 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1716 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1717 | if (ret) |
| 1718 | goto err; |
| 1719 | |
| 1720 | if (data->o_res.delegation_type != 0) |
| 1721 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1722 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1723 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1724 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1725 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1726 | |
| 1727 | return state; |
| 1728 | err: |
| 1729 | return ERR_PTR(ret); |
| 1730 | |
| 1731 | } |
| 1732 | |
| 1733 | static struct nfs4_state * |
| 1734 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1735 | { |
| 1736 | struct inode *inode; |
| 1737 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1738 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1739 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1740 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1741 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1742 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1743 | goto out; |
| 1744 | } |
| 1745 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1746 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1747 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1748 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1749 | 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] | 1750 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1751 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1752 | goto err; |
| 1753 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1754 | state = nfs4_get_open_state(inode, data->owner); |
| 1755 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1756 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1757 | if (data->o_res.delegation_type != 0) |
| 1758 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1759 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1760 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1761 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1762 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1763 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1764 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1765 | err_put_inode: |
| 1766 | iput(inode); |
| 1767 | err: |
| 1768 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1771 | static struct nfs4_state * |
| 1772 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1773 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1774 | struct nfs4_state *ret; |
| 1775 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1776 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1777 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1778 | else |
| 1779 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1780 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1781 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1782 | } |
| 1783 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1785 | { |
| 1786 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1787 | struct nfs_open_context *ctx; |
| 1788 | |
| 1789 | spin_lock(&state->inode->i_lock); |
| 1790 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1791 | if (ctx->state != state) |
| 1792 | continue; |
| 1793 | get_nfs_open_context(ctx); |
| 1794 | spin_unlock(&state->inode->i_lock); |
| 1795 | return ctx; |
| 1796 | } |
| 1797 | spin_unlock(&state->inode->i_lock); |
| 1798 | return ERR_PTR(-ENOENT); |
| 1799 | } |
| 1800 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1801 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1802 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1803 | { |
| 1804 | struct nfs4_opendata *opendata; |
| 1805 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1806 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1807 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1808 | if (opendata == NULL) |
| 1809 | return ERR_PTR(-ENOMEM); |
| 1810 | opendata->state = state; |
| 1811 | atomic_inc(&state->count); |
| 1812 | return opendata; |
| 1813 | } |
| 1814 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1815 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1816 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1817 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1818 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1819 | int ret; |
| 1820 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1821 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1822 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1823 | opendata->o_arg.open_flags = 0; |
| 1824 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1825 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1826 | NFS_SB(opendata->dentry->d_sb), |
| 1827 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1828 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1829 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1830 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1831 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1832 | if (ret != 0) |
| 1833 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1834 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1835 | if (IS_ERR(newstate)) |
| 1836 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1837 | if (newstate != opendata->state) |
| 1838 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1839 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1840 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1844 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1845 | int ret; |
| 1846 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1847 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1848 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1849 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1850 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1851 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1852 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1853 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1854 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1855 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1856 | if (ret != 0) |
| 1857 | return ret; |
| 1858 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1859 | if (ret != 0) |
| 1860 | return ret; |
| 1861 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1862 | if (ret != 0) |
| 1863 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1864 | /* |
| 1865 | * We may have performed cached opens for all three recoveries. |
| 1866 | * Check if we need to update the current stateid. |
| 1867 | */ |
| 1868 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1869 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1870 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1871 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1872 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1873 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1874 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1875 | return 0; |
| 1876 | } |
| 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | /* |
| 1879 | * OPEN_RECLAIM: |
| 1880 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1882 | 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] | 1883 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1884 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1885 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1886 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | int status; |
| 1888 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1889 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1890 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1891 | if (IS_ERR(opendata)) |
| 1892 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1893 | rcu_read_lock(); |
| 1894 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1895 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1896 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1897 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1898 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1899 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1900 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | return status; |
| 1902 | } |
| 1903 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1904 | 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] | 1905 | { |
| 1906 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1907 | struct nfs4_exception exception = { }; |
| 1908 | int err; |
| 1909 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1910 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1911 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1912 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1913 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1914 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1915 | break; |
| 1916 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } while (exception.retry); |
| 1918 | return err; |
| 1919 | } |
| 1920 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1921 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1922 | { |
| 1923 | struct nfs_open_context *ctx; |
| 1924 | int ret; |
| 1925 | |
| 1926 | ctx = nfs4_state_find_open_context(state); |
| 1927 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1928 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1929 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1930 | put_nfs_open_context(ctx); |
| 1931 | return ret; |
| 1932 | } |
| 1933 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1934 | 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] | 1935 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1936 | switch (err) { |
| 1937 | default: |
| 1938 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1939 | "%d.\n", __func__, err); |
| 1940 | case 0: |
| 1941 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1942 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1943 | case -ESTALE: |
| 1944 | break; |
| 1945 | case -NFS4ERR_BADSESSION: |
| 1946 | case -NFS4ERR_BADSLOT: |
| 1947 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1948 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1949 | case -NFS4ERR_DEADSESSION: |
| 1950 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1951 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1952 | return -EAGAIN; |
| 1953 | case -NFS4ERR_STALE_CLIENTID: |
| 1954 | case -NFS4ERR_STALE_STATEID: |
| 1955 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1956 | /* Don't recall a delegation if it was lost */ |
| 1957 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1958 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1959 | case -NFS4ERR_MOVED: |
| 1960 | nfs4_schedule_migration_recovery(server); |
| 1961 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1962 | case -NFS4ERR_LEASE_MOVED: |
| 1963 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1964 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1965 | case -NFS4ERR_DELEG_REVOKED: |
| 1966 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1967 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1968 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1969 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1970 | nfs_inode_find_state_and_recover(state->inode, |
| 1971 | stateid); |
| 1972 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1973 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1974 | case -NFS4ERR_DELAY: |
| 1975 | case -NFS4ERR_GRACE: |
| 1976 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1977 | ssleep(1); |
| 1978 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1979 | case -ENOMEM: |
| 1980 | case -NFS4ERR_DENIED: |
| 1981 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1982 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | return err; |
| 1985 | } |
| 1986 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1987 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1988 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1989 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1990 | { |
| 1991 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1992 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1993 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1994 | |
| 1995 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1996 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1997 | if (IS_ERR(opendata)) |
| 1998 | return PTR_ERR(opendata); |
| 1999 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2000 | write_seqlock(&state->seqlock); |
| 2001 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2002 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2003 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2004 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2005 | case FMODE_READ|FMODE_WRITE: |
| 2006 | case FMODE_WRITE: |
| 2007 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2008 | if (err) |
| 2009 | break; |
| 2010 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2011 | if (err) |
| 2012 | break; |
| 2013 | case FMODE_READ: |
| 2014 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2015 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2016 | nfs4_opendata_put(opendata); |
| 2017 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2018 | } |
| 2019 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2020 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2021 | { |
| 2022 | struct nfs4_opendata *data = calldata; |
| 2023 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2024 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2025 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2028 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2029 | { |
| 2030 | struct nfs4_opendata *data = calldata; |
| 2031 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2032 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2033 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2034 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2035 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2036 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2037 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2038 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2039 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2040 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | static void nfs4_open_confirm_release(void *calldata) |
| 2044 | { |
| 2045 | struct nfs4_opendata *data = calldata; |
| 2046 | struct nfs4_state *state = NULL; |
| 2047 | |
| 2048 | /* If this request hasn't been cancelled, do nothing */ |
| 2049 | if (data->cancelled == 0) |
| 2050 | goto out_free; |
| 2051 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2052 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2053 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2054 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2055 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2056 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2057 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2058 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2062 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2063 | .rpc_call_done = nfs4_open_confirm_done, |
| 2064 | .rpc_release = nfs4_open_confirm_release, |
| 2065 | }; |
| 2066 | |
| 2067 | /* |
| 2068 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2069 | */ |
| 2070 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2071 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2072 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2073 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2074 | struct rpc_message msg = { |
| 2075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2076 | .rpc_argp = &data->c_arg, |
| 2077 | .rpc_resp = &data->c_res, |
| 2078 | .rpc_cred = data->owner->so_cred, |
| 2079 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2080 | struct rpc_task_setup task_setup_data = { |
| 2081 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2082 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2083 | .callback_ops = &nfs4_open_confirm_ops, |
| 2084 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2085 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2086 | .flags = RPC_TASK_ASYNC, |
| 2087 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | int status; |
| 2089 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2090 | 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] | 2091 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2092 | data->rpc_done = 0; |
| 2093 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2094 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2095 | if (data->is_recover) |
| 2096 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2097 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2098 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2099 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2100 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2101 | if (status != 0) { |
| 2102 | data->cancelled = 1; |
| 2103 | smp_wmb(); |
| 2104 | } else |
| 2105 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2106 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | return status; |
| 2108 | } |
| 2109 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2110 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2112 | struct nfs4_opendata *data = calldata; |
| 2113 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2114 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2115 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2116 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2117 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2118 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2119 | /* |
| 2120 | * Check if we still need to send an OPEN call, or if we can use |
| 2121 | * a delegation instead. |
| 2122 | */ |
| 2123 | if (data->state != NULL) { |
| 2124 | struct nfs_delegation *delegation; |
| 2125 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2126 | 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] | 2127 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2128 | rcu_read_lock(); |
| 2129 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2130 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2131 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2132 | rcu_read_unlock(); |
| 2133 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2134 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2135 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2136 | switch (claim) { |
| 2137 | default: |
| 2138 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2139 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2140 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2141 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2142 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2143 | case NFS4_OPEN_CLAIM_FH: |
| 2144 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2145 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2146 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2147 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2148 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2149 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2150 | &data->o_res.seq_res, |
| 2151 | task) != 0) |
| 2152 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2153 | |
| 2154 | /* Set the create mode (note dependency on the session type) */ |
| 2155 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2156 | if (data->o_arg.open_flags & O_EXCL) { |
| 2157 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2158 | if (nfs4_has_persistent_session(clp)) |
| 2159 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2160 | else if (clp->cl_mvops->minor_version > 0) |
| 2161 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2162 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2163 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2164 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2165 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2166 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2167 | out_no_action: |
| 2168 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2169 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2170 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2173 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2174 | { |
| 2175 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2177 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2178 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2179 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2180 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2181 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2182 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2183 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2184 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2185 | case S_IFREG: |
| 2186 | break; |
| 2187 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2188 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2189 | break; |
| 2190 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2192 | break; |
| 2193 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2194 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2195 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2196 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2197 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2198 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2199 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2200 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2201 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2202 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2203 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2204 | static void nfs4_open_release(void *calldata) |
| 2205 | { |
| 2206 | struct nfs4_opendata *data = calldata; |
| 2207 | struct nfs4_state *state = NULL; |
| 2208 | |
| 2209 | /* If this request hasn't been cancelled, do nothing */ |
| 2210 | if (data->cancelled == 0) |
| 2211 | goto out_free; |
| 2212 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2213 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2214 | goto out_free; |
| 2215 | /* In case we need an open_confirm, no cleanup! */ |
| 2216 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2217 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2218 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2219 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2220 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2221 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2222 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2226 | .rpc_call_prepare = nfs4_open_prepare, |
| 2227 | .rpc_call_done = nfs4_open_done, |
| 2228 | .rpc_release = nfs4_open_release, |
| 2229 | }; |
| 2230 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2231 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2232 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2233 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2234 | struct nfs_server *server = NFS_SERVER(dir); |
| 2235 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2236 | struct nfs_openres *o_res = &data->o_res; |
| 2237 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2238 | struct rpc_message msg = { |
| 2239 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2240 | .rpc_argp = o_arg, |
| 2241 | .rpc_resp = o_res, |
| 2242 | .rpc_cred = data->owner->so_cred, |
| 2243 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2244 | struct rpc_task_setup task_setup_data = { |
| 2245 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2246 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2247 | .callback_ops = &nfs4_open_ops, |
| 2248 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2249 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2250 | .flags = RPC_TASK_ASYNC, |
| 2251 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2252 | int status; |
| 2253 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2254 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2255 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2256 | data->rpc_done = 0; |
| 2257 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2258 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2259 | data->is_recover = 0; |
| 2260 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2261 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2262 | data->is_recover = 1; |
| 2263 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2264 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2265 | if (IS_ERR(task)) |
| 2266 | return PTR_ERR(task); |
| 2267 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2268 | if (status != 0) { |
| 2269 | data->cancelled = 1; |
| 2270 | smp_wmb(); |
| 2271 | } else |
| 2272 | status = data->rpc_status; |
| 2273 | rpc_put_task(task); |
| 2274 | |
| 2275 | return status; |
| 2276 | } |
| 2277 | |
| 2278 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2279 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2280 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2281 | struct nfs_openres *o_res = &data->o_res; |
| 2282 | int status; |
| 2283 | |
| 2284 | status = nfs4_run_open_task(data, 1); |
| 2285 | if (status != 0 || !data->rpc_done) |
| 2286 | return status; |
| 2287 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2288 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2289 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2290 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2291 | status = _nfs4_proc_open_confirm(data); |
| 2292 | if (status != 0) |
| 2293 | return status; |
| 2294 | } |
| 2295 | |
| 2296 | return status; |
| 2297 | } |
| 2298 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2299 | /* |
| 2300 | * Additional permission checks in order to distinguish between an |
| 2301 | * open for read, and an open for execute. This works around the |
| 2302 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2303 | * the same. |
| 2304 | * Note that in the non-execute case, we want to turn off permission |
| 2305 | * checking if we just created a new file (POSIX open() semantics). |
| 2306 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2307 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2308 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2309 | struct nfs4_state *state, fmode_t fmode, |
| 2310 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2311 | { |
| 2312 | struct nfs_access_entry cache; |
| 2313 | u32 mask; |
| 2314 | |
| 2315 | /* access call failed or for some reason the server doesn't |
| 2316 | * support any access modes -- defer access call until later */ |
| 2317 | if (opendata->o_res.access_supported == 0) |
| 2318 | return 0; |
| 2319 | |
| 2320 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2321 | /* |
| 2322 | * Use openflags to check for exec, because fmode won't |
| 2323 | * always have FMODE_EXEC set when file open for exec. |
| 2324 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2325 | if (openflags & __FMODE_EXEC) { |
| 2326 | /* ONLY check for exec rights */ |
| 2327 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2328 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2329 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2330 | |
| 2331 | cache.cred = cred; |
| 2332 | cache.jiffies = jiffies; |
| 2333 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2334 | nfs_access_add_cache(state->inode, &cache); |
| 2335 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2336 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2337 | return 0; |
| 2338 | |
| 2339 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2340 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2341 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2342 | } |
| 2343 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2344 | /* |
| 2345 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2346 | */ |
| 2347 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2348 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2349 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2350 | struct nfs_server *server = NFS_SERVER(dir); |
| 2351 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2352 | struct nfs_openres *o_res = &data->o_res; |
| 2353 | int status; |
| 2354 | |
| 2355 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2356 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2357 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2358 | if (status != 0) { |
| 2359 | if (status == -NFS4ERR_BADNAME && |
| 2360 | !(o_arg->open_flags & O_CREAT)) |
| 2361 | return -ENOENT; |
| 2362 | return status; |
| 2363 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2364 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2365 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2366 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2367 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2368 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2369 | if (o_arg->open_flags & O_EXCL) |
| 2370 | data->file_created = 1; |
| 2371 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2372 | data->file_created = 1; |
| 2373 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2374 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2375 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2377 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2379 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } |
| 2381 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2382 | 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] | 2383 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2386 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2387 | { |
| 2388 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2389 | } |
| 2390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | /* |
| 2392 | * OPEN_EXPIRED: |
| 2393 | * reclaim state on the server after a network partition. |
| 2394 | * Assumes caller holds the appropriate lock |
| 2395 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2396 | 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] | 2397 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2398 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2399 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2401 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2402 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2403 | if (IS_ERR(opendata)) |
| 2404 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2405 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2406 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2407 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2408 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2409 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2412 | 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] | 2413 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2414 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2415 | struct nfs4_exception exception = { }; |
| 2416 | int err; |
| 2417 | |
| 2418 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2419 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2420 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2421 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2422 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2423 | switch (err) { |
| 2424 | default: |
| 2425 | goto out; |
| 2426 | case -NFS4ERR_GRACE: |
| 2427 | case -NFS4ERR_DELAY: |
| 2428 | nfs4_handle_exception(server, err, &exception); |
| 2429 | err = 0; |
| 2430 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2431 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2432 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2433 | return err; |
| 2434 | } |
| 2435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2437 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2439 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2441 | ctx = nfs4_state_find_open_context(state); |
| 2442 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2443 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2444 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2445 | put_nfs_open_context(ctx); |
| 2446 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2449 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2450 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2451 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2452 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2453 | write_seqlock(&state->seqlock); |
| 2454 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2455 | write_sequnlock(&state->seqlock); |
| 2456 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2457 | } |
| 2458 | |
| 2459 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2460 | { |
| 2461 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2462 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2466 | { |
| 2467 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2468 | nfs40_clear_delegation_stateid(state); |
| 2469 | return nfs4_open_expired(sp, state); |
| 2470 | } |
| 2471 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2472 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2473 | nfs4_stateid *stateid, |
| 2474 | struct rpc_cred *cred) |
| 2475 | { |
| 2476 | return -NFS4ERR_BAD_STATEID; |
| 2477 | } |
| 2478 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2479 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2480 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2481 | nfs4_stateid *stateid, |
| 2482 | struct rpc_cred *cred) |
| 2483 | { |
| 2484 | int status; |
| 2485 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2486 | switch (stateid->type) { |
| 2487 | default: |
| 2488 | break; |
| 2489 | case NFS4_INVALID_STATEID_TYPE: |
| 2490 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2491 | return -NFS4ERR_BAD_STATEID; |
| 2492 | case NFS4_REVOKED_STATEID_TYPE: |
| 2493 | goto out_free; |
| 2494 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2495 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2496 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2497 | switch (status) { |
| 2498 | case -NFS4ERR_EXPIRED: |
| 2499 | case -NFS4ERR_ADMIN_REVOKED: |
| 2500 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2501 | break; |
| 2502 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2503 | return status; |
| 2504 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2505 | out_free: |
| 2506 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2507 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2508 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2509 | } |
| 2510 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2511 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2512 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2513 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2514 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2515 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2516 | struct rpc_cred *cred; |
| 2517 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2518 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2519 | /* Get the delegation credential for use by test/free_stateid */ |
| 2520 | rcu_read_lock(); |
| 2521 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2522 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2523 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2524 | return; |
| 2525 | } |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2526 | |
| 2527 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2528 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2529 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2530 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2531 | return; |
| 2532 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2533 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2534 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2535 | rcu_read_unlock(); |
| 2536 | return; |
| 2537 | } |
| 2538 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2539 | cred = get_rpccred(delegation->cred); |
| 2540 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2541 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2542 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2543 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2544 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2545 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2546 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2550 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2551 | * |
| 2552 | * @state: NFSv4 state for an inode |
| 2553 | * |
| 2554 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2555 | * Otherwise a negative NFS4ERR value is returned. |
| 2556 | */ |
| 2557 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2558 | { |
| 2559 | int status, ret = NFS_OK; |
| 2560 | struct nfs4_lock_state *lsp; |
| 2561 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2562 | |
| 2563 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2564 | goto out; |
| 2565 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2566 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2567 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2568 | |
| 2569 | status = nfs41_test_and_free_expired_stateid(server, |
| 2570 | &lsp->ls_stateid, |
| 2571 | cred); |
| 2572 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2573 | if (status == -NFS4ERR_EXPIRED || |
| 2574 | status == -NFS4ERR_BAD_STATEID) { |
| 2575 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2576 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2577 | if (!recover_lost_locks) |
| 2578 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2579 | } else if (status != NFS_OK) { |
| 2580 | ret = status; |
| 2581 | break; |
| 2582 | } |
| 2583 | } |
| 2584 | }; |
| 2585 | out: |
| 2586 | return ret; |
| 2587 | } |
| 2588 | |
| 2589 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2590 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2591 | * |
| 2592 | * @state: NFSv4 state for an inode |
| 2593 | * |
| 2594 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2595 | * Otherwise a negative NFS4ERR value is returned. |
| 2596 | */ |
| 2597 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2598 | { |
| 2599 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2600 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2601 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2602 | int status; |
| 2603 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2604 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame^] | 2605 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2606 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2607 | return NFS_OK; |
| 2608 | return -NFS4ERR_OPENMODE; |
| 2609 | } |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2610 | return -NFS4ERR_BAD_STATEID; |
| 2611 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2612 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2613 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2614 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2615 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2616 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2617 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2618 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2619 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2620 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame^] | 2621 | if (status != NFS_OK) |
| 2622 | return status; |
| 2623 | if (nfs_open_stateid_recover_openmode(state)) |
| 2624 | return -NFS4ERR_OPENMODE; |
| 2625 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2629 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2630 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2631 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2632 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2633 | status = nfs41_check_expired_locks(state); |
| 2634 | if (status != NFS_OK) |
| 2635 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2636 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2637 | if (status != NFS_OK) |
| 2638 | status = nfs4_open_expired(sp, state); |
| 2639 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2640 | } |
| 2641 | #endif |
| 2642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2644 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2645 | * fields corresponding to attributes that were used to store the verifier. |
| 2646 | * Make sure we clobber those fields in the later setattr call |
| 2647 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2648 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2649 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2650 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2651 | const u32 *attrset = opendata->o_res.attrset; |
| 2652 | |
| 2653 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2654 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2655 | sattr->ia_valid |= ATTR_ATIME; |
| 2656 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2657 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2658 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2659 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2660 | |
| 2661 | /* Except MODE, it seems harmless of setting twice. */ |
| 2662 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2663 | sattr->ia_valid &= ~ATTR_MODE; |
| 2664 | |
| 2665 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2666 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2667 | } |
| 2668 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2669 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2670 | fmode_t fmode, |
| 2671 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2672 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2673 | { |
| 2674 | struct nfs4_state_owner *sp = opendata->owner; |
| 2675 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2676 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2677 | struct nfs4_state *state; |
| 2678 | unsigned int seq; |
| 2679 | int ret; |
| 2680 | |
| 2681 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2682 | |
| 2683 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2684 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2685 | goto out; |
| 2686 | |
| 2687 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2688 | ret = PTR_ERR(state); |
| 2689 | if (IS_ERR(state)) |
| 2690 | goto out; |
| 2691 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2692 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2693 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2694 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2695 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2696 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2697 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2698 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2699 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2700 | alias = d_exact_alias(dentry, state->inode); |
| 2701 | if (!alias) |
| 2702 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2703 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2704 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2705 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2706 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2707 | } |
| 2708 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2709 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2710 | } |
| 2711 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2712 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2713 | if (ret != 0) |
| 2714 | goto out; |
| 2715 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2716 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2717 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2718 | nfs_inode_attach_open_context(ctx); |
| 2719 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2720 | nfs4_schedule_stateid_recovery(server, state); |
| 2721 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2722 | out: |
| 2723 | return ret; |
| 2724 | } |
| 2725 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2726 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2727 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2729 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2730 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2731 | int flags, |
| 2732 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2733 | struct nfs4_label *label, |
| 2734 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | { |
| 2736 | struct nfs4_state_owner *sp; |
| 2737 | struct nfs4_state *state = NULL; |
| 2738 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2739 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2740 | struct dentry *dentry = ctx->dentry; |
| 2741 | struct rpc_cred *cred = ctx->cred; |
| 2742 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2743 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2744 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2745 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2746 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
| 2748 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2750 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2751 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2753 | goto out_err; |
| 2754 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2755 | status = nfs4_recover_expired_lease(server); |
| 2756 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2757 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2758 | if (d_really_is_positive(dentry)) |
| 2759 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2760 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2761 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2762 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2763 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2764 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2765 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2766 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2768 | if (label) { |
| 2769 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2770 | if (IS_ERR(olabel)) { |
| 2771 | status = PTR_ERR(olabel); |
| 2772 | goto err_opendata_put; |
| 2773 | } |
| 2774 | } |
| 2775 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2776 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2777 | if (!opendata->f_attr.mdsthreshold) { |
| 2778 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2779 | if (!opendata->f_attr.mdsthreshold) |
| 2780 | goto err_free_label; |
| 2781 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2782 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2783 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2784 | if (d_really_is_positive(dentry)) |
| 2785 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2786 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2787 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2788 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2789 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2790 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2791 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2792 | 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] | 2793 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2794 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2795 | /* |
| 2796 | * send create attributes which was not set by open |
| 2797 | * with an extra setattr. |
| 2798 | */ |
| 2799 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2800 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2801 | status = nfs4_do_setattr(state->inode, cred, |
| 2802 | opendata->o_res.f_attr, sattr, |
| 2803 | state, label, olabel); |
| 2804 | if (status == 0) { |
| 2805 | nfs_setattr_update_inode(state->inode, sattr, |
| 2806 | opendata->o_res.f_attr); |
| 2807 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2808 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2809 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2810 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2811 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2812 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2813 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2814 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2815 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2816 | opendata->f_attr.mdsthreshold = NULL; |
| 2817 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2818 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2819 | nfs4_label_free(olabel); |
| 2820 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2821 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2824 | err_free_label: |
| 2825 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2826 | err_opendata_put: |
| 2827 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2828 | err_put_state_owner: |
| 2829 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | return status; |
| 2832 | } |
| 2833 | |
| 2834 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2835 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2836 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2837 | int flags, |
| 2838 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2839 | struct nfs4_label *label, |
| 2840 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2842 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | struct nfs4_exception exception = { }; |
| 2844 | struct nfs4_state *res; |
| 2845 | int status; |
| 2846 | |
| 2847 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2848 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2849 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2850 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | if (status == 0) |
| 2852 | break; |
| 2853 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2854 | * book-keeping w.r.t. state-changing operations |
| 2855 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2856 | * It is actually a sign of a bug on the client or on the server. |
| 2857 | * |
| 2858 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2859 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | * have unhashed the old state_owner for us, and that we can |
| 2861 | * therefore safely retry using a new one. We should still warn |
| 2862 | * the user though... |
| 2863 | */ |
| 2864 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2865 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2866 | " returned a bad sequence-id error!\n", |
| 2867 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | exception.retry = 1; |
| 2869 | continue; |
| 2870 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2871 | /* |
| 2872 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2873 | * state before it received the OPEN_CONFIRM. |
| 2874 | * Recover by retrying the request as per the discussion |
| 2875 | * on Page 181 of RFC3530. |
| 2876 | */ |
| 2877 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2878 | exception.retry = 1; |
| 2879 | continue; |
| 2880 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2881 | if (status == -EAGAIN) { |
| 2882 | /* We must have found a delegation */ |
| 2883 | exception.retry = 1; |
| 2884 | continue; |
| 2885 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2886 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2887 | continue; |
| 2888 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | status, &exception)); |
| 2890 | } while (exception.retry); |
| 2891 | return res; |
| 2892 | } |
| 2893 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2894 | static int _nfs4_do_setattr(struct inode *inode, |
| 2895 | struct nfs_setattrargs *arg, |
| 2896 | struct nfs_setattrres *res, |
| 2897 | struct rpc_cred *cred, |
| 2898 | struct nfs4_state *state) |
| 2899 | { |
| 2900 | struct nfs_server *server = NFS_SERVER(inode); |
| 2901 | struct rpc_message msg = { |
| 2902 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2903 | .rpc_argp = arg, |
| 2904 | .rpc_resp = res, |
| 2905 | .rpc_cred = cred, |
| 2906 | }; |
| 2907 | struct rpc_cred *delegation_cred = NULL; |
| 2908 | unsigned long timestamp = jiffies; |
| 2909 | fmode_t fmode; |
| 2910 | bool truncate; |
| 2911 | int status; |
| 2912 | |
| 2913 | nfs_fattr_init(res->fattr); |
| 2914 | |
| 2915 | /* Servers should only apply open mode checks for file size changes */ |
| 2916 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2917 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2918 | |
| 2919 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2920 | /* Use that stateid */ |
| 2921 | } else if (truncate && state != NULL) { |
| 2922 | struct nfs_lockowner lockowner = { |
| 2923 | .l_owner = current->files, |
| 2924 | .l_pid = current->tgid, |
| 2925 | }; |
| 2926 | if (!nfs4_valid_open_stateid(state)) |
| 2927 | return -EBADF; |
| 2928 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2929 | &arg->stateid, &delegation_cred) == -EIO) |
| 2930 | return -EBADF; |
| 2931 | } else |
| 2932 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2933 | if (delegation_cred) |
| 2934 | msg.rpc_cred = delegation_cred; |
| 2935 | |
| 2936 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2937 | |
| 2938 | put_rpccred(delegation_cred); |
| 2939 | if (status == 0 && state != NULL) |
| 2940 | renew_lease(server, timestamp); |
| 2941 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2942 | return status; |
| 2943 | } |
| 2944 | |
| 2945 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2946 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2947 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2948 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2950 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2952 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | .iap = sattr, |
| 2954 | .server = server, |
| 2955 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2956 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | }; |
| 2958 | struct nfs_setattrres res = { |
| 2959 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2960 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | .server = server, |
| 2962 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2963 | struct nfs4_exception exception = { |
| 2964 | .state = state, |
| 2965 | .inode = inode, |
| 2966 | .stateid = &arg.stateid, |
| 2967 | }; |
| 2968 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2970 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2971 | if (ilabel) |
| 2972 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2975 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2976 | switch (err) { |
| 2977 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2978 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2979 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2980 | "applying open mode checks to " |
| 2981 | "a SETATTR that is not " |
| 2982 | "changing file size.\n", |
| 2983 | server->nfs_client->cl_hostname); |
| 2984 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2985 | if (state && !(state->state & FMODE_WRITE)) { |
| 2986 | err = -EBADF; |
| 2987 | if (sattr->ia_valid & ATTR_OPEN) |
| 2988 | err = -EACCES; |
| 2989 | goto out; |
| 2990 | } |
| 2991 | } |
| 2992 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2994 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | return err; |
| 2996 | } |
| 2997 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2998 | static bool |
| 2999 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3000 | { |
| 3001 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3002 | return false; |
| 3003 | |
| 3004 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3005 | } |
| 3006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | struct nfs4_closedata { |
| 3008 | struct inode *inode; |
| 3009 | struct nfs4_state *state; |
| 3010 | struct nfs_closeargs arg; |
| 3011 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3012 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3013 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3014 | bool roc; |
| 3015 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | }; |
| 3017 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3018 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3019 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3020 | struct nfs4_closedata *calldata = data; |
| 3021 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3022 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3023 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3024 | if (calldata->roc) |
| 3025 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3026 | nfs4_put_open_state(calldata->state); |
| 3027 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3028 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3029 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3030 | kfree(calldata); |
| 3031 | } |
| 3032 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3033 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3035 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3038 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3040 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3041 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3042 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3043 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | /* hmm. we are done with the inode, and in the process of freeing |
| 3045 | * the state_owner. we keep this around to process errors |
| 3046 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | switch (task->tk_status) { |
| 3048 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3049 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3050 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3051 | pnfs_roc_set_barrier(state->inode, |
| 3052 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3053 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3054 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3055 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3057 | case -NFS4ERR_EXPIRED: |
| 3058 | nfs4_free_revoked_stateid(server, |
| 3059 | &calldata->arg.stateid, |
| 3060 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3061 | case -NFS4ERR_OLD_STATEID: |
| 3062 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3063 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3064 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3065 | rpc_restart_call_prepare(task); |
| 3066 | goto out_release; |
| 3067 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3068 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3069 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3071 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3072 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3073 | goto out_release; |
| 3074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3076 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3077 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3078 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3079 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3080 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3081 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3084 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3086 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3087 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3088 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3089 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3090 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3091 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3092 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3093 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3094 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3095 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3096 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3097 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3098 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3099 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3100 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3101 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3102 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3103 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3104 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3105 | if (state->n_rdonly == 0) |
| 3106 | call_close |= is_rdonly; |
| 3107 | else if (is_rdonly) |
| 3108 | calldata->arg.fmode |= FMODE_READ; |
| 3109 | if (state->n_wronly == 0) |
| 3110 | call_close |= is_wronly; |
| 3111 | else if (is_wronly) |
| 3112 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3113 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3114 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3115 | } else if (is_rdwr) |
| 3116 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3117 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3118 | if (!nfs4_valid_open_stateid(state)) |
| 3119 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3120 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3121 | |
| 3122 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3123 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3124 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3125 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3126 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3127 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 3128 | nfs_release_seqid(calldata->arg.seqid); |
| 3129 | goto out_wait; |
| 3130 | } |
| 3131 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3132 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3133 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3134 | if (calldata->roc) |
| 3135 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 3136 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3137 | calldata->arg.share_access = |
| 3138 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3139 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3140 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3141 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3142 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3143 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3144 | &calldata->arg.seq_args, |
| 3145 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3146 | task) != 0) |
| 3147 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3148 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3149 | return; |
| 3150 | out_no_action: |
| 3151 | task->tk_action = NULL; |
| 3152 | out_wait: |
| 3153 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3156 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3157 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3158 | .rpc_call_done = nfs4_close_done, |
| 3159 | .rpc_release = nfs4_free_closedata, |
| 3160 | }; |
| 3161 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3162 | static bool nfs4_roc(struct inode *inode) |
| 3163 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3164 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3165 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3166 | return pnfs_roc(inode); |
| 3167 | } |
| 3168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | /* |
| 3170 | * It is possible for data to be read/written from a mem-mapped file |
| 3171 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3172 | * This means that we can't safely call nfsv4 close on a file until |
| 3173 | * the inode is cleared. This in turn means that we are not good |
| 3174 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3175 | * share state even when we are done with one of the three share |
| 3176 | * stateid's in the inode. |
| 3177 | * |
| 3178 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3179 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3180 | 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] | 3181 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3182 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3183 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3185 | struct nfs4_state_owner *sp = state->owner; |
| 3186 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3187 | struct rpc_message msg = { |
| 3188 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3189 | .rpc_cred = state->owner->so_cred, |
| 3190 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3191 | struct rpc_task_setup task_setup_data = { |
| 3192 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3193 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3194 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3195 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3196 | .flags = RPC_TASK_ASYNC, |
| 3197 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3198 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3200 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3201 | &task_setup_data.rpc_client, &msg); |
| 3202 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3203 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3205 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3206 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3207 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3209 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3211 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3212 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3213 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3214 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3215 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3216 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3217 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3218 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3219 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3220 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3221 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3222 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3223 | msg.rpc_argp = &calldata->arg; |
| 3224 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3225 | task_setup_data.callback_data = calldata; |
| 3226 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3227 | if (IS_ERR(task)) |
| 3228 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3229 | status = 0; |
| 3230 | if (wait) |
| 3231 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3232 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3233 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3234 | out_free_calldata: |
| 3235 | kfree(calldata); |
| 3236 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3237 | nfs4_put_open_state(state); |
| 3238 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3239 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3242 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3243 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3244 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3247 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3248 | |
| 3249 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3251 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3252 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3253 | |
| 3254 | nfs4_label_release_security(label); |
| 3255 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3256 | if (IS_ERR(state)) |
| 3257 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3258 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3261 | 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] | 3262 | { |
| 3263 | if (ctx->state == NULL) |
| 3264 | return; |
| 3265 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3266 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3267 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3268 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3271 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3272 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3273 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3276 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3277 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3278 | struct nfs4_server_caps_arg args = { |
| 3279 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3280 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3281 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | struct nfs4_server_caps_res res = {}; |
| 3283 | struct rpc_message msg = { |
| 3284 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3285 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | .rpc_resp = &res, |
| 3287 | }; |
| 3288 | int status; |
| 3289 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3290 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3291 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3292 | FATTR4_WORD0_LINK_SUPPORT | |
| 3293 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3294 | FATTR4_WORD0_ACLSUPPORT; |
| 3295 | if (minorversion) |
| 3296 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3297 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3298 | 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] | 3299 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3300 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3301 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3302 | case 0: |
| 3303 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3304 | res.attr_bitmask[2] = 0; |
| 3305 | break; |
| 3306 | case 1: |
| 3307 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3308 | break; |
| 3309 | case 2: |
| 3310 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3313 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3314 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3315 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3316 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3317 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3318 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3319 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3320 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | server->caps |= NFS_CAP_ACLS; |
| 3322 | if (res.has_links != 0) |
| 3323 | server->caps |= NFS_CAP_HARDLINKS; |
| 3324 | if (res.has_symlinks != 0) |
| 3325 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3326 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3327 | server->caps |= NFS_CAP_FILEID; |
| 3328 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3329 | server->caps |= NFS_CAP_MODE; |
| 3330 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3331 | server->caps |= NFS_CAP_NLINK; |
| 3332 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3333 | server->caps |= NFS_CAP_OWNER; |
| 3334 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3335 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3336 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3337 | server->caps |= NFS_CAP_ATIME; |
| 3338 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3339 | server->caps |= NFS_CAP_CTIME; |
| 3340 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3341 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3342 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3343 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3344 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3345 | #endif |
| 3346 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3347 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3348 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3349 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3350 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3351 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3352 | 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] | 3353 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3354 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3355 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3357 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | return status; |
| 3361 | } |
| 3362 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3363 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | { |
| 3365 | struct nfs4_exception exception = { }; |
| 3366 | int err; |
| 3367 | do { |
| 3368 | err = nfs4_handle_exception(server, |
| 3369 | _nfs4_server_capabilities(server, fhandle), |
| 3370 | &exception); |
| 3371 | } while (exception.retry); |
| 3372 | return err; |
| 3373 | } |
| 3374 | |
| 3375 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3376 | struct nfs_fsinfo *info) |
| 3377 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3378 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3380 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | }; |
| 3382 | struct nfs4_lookup_res res = { |
| 3383 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3384 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | .fh = fhandle, |
| 3386 | }; |
| 3387 | struct rpc_message msg = { |
| 3388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3389 | .rpc_argp = &args, |
| 3390 | .rpc_resp = &res, |
| 3391 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3392 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3393 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3394 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3395 | /* |
| 3396 | * Process the label in the upcoming getfattr |
| 3397 | */ |
| 3398 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3399 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3400 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3401 | 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] | 3402 | } |
| 3403 | |
| 3404 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3405 | struct nfs_fsinfo *info) |
| 3406 | { |
| 3407 | struct nfs4_exception exception = { }; |
| 3408 | int err; |
| 3409 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3410 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3411 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3412 | switch (err) { |
| 3413 | case 0: |
| 3414 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3415 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3416 | default: |
| 3417 | err = nfs4_handle_exception(server, err, &exception); |
| 3418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3420 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | return err; |
| 3422 | } |
| 3423 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3424 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3425 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3426 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3427 | struct rpc_auth_create_args auth_args = { |
| 3428 | .pseudoflavor = flavor, |
| 3429 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3430 | struct rpc_auth *auth; |
| 3431 | int ret; |
| 3432 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3433 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3434 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3435 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3436 | goto out; |
| 3437 | } |
| 3438 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3439 | out: |
| 3440 | return ret; |
| 3441 | } |
| 3442 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3443 | /* |
| 3444 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3445 | * |
| 3446 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3447 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3448 | * |
| 3449 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3450 | * negative errno value. |
| 3451 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3452 | 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] | 3453 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3455 | /* Per 3530bis 15.33.5 */ |
| 3456 | static const rpc_authflavor_t flav_array[] = { |
| 3457 | RPC_AUTH_GSS_KRB5P, |
| 3458 | RPC_AUTH_GSS_KRB5I, |
| 3459 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3460 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3461 | RPC_AUTH_NULL, |
| 3462 | }; |
| 3463 | int status = -EPERM; |
| 3464 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3466 | if (server->auth_info.flavor_len > 0) { |
| 3467 | /* try each flavor specified by user */ |
| 3468 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3469 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3470 | server->auth_info.flavors[i]); |
| 3471 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3472 | continue; |
| 3473 | break; |
| 3474 | } |
| 3475 | } else { |
| 3476 | /* no flavors specified by user, try default list */ |
| 3477 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3478 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3479 | flav_array[i]); |
| 3480 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3481 | continue; |
| 3482 | break; |
| 3483 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3484 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3485 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3486 | /* |
| 3487 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3488 | * to access the mount. It could also mean that we tried to mount |
| 3489 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3490 | * existing mount programs don't handle -EACCES very well so it should |
| 3491 | * be mapped to -EPERM instead. |
| 3492 | */ |
| 3493 | if (status == -EACCES) |
| 3494 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3495 | return status; |
| 3496 | } |
| 3497 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3498 | /** |
| 3499 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3500 | * @server: initialized nfs_server handle |
| 3501 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3502 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3503 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3504 | * |
| 3505 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3506 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3507 | 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] | 3508 | struct nfs_fsinfo *info, |
| 3509 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3510 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3511 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3512 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3513 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3514 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3515 | |
| 3516 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3517 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3518 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | if (status == 0) |
| 3521 | status = nfs4_server_capabilities(server, fhandle); |
| 3522 | if (status == 0) |
| 3523 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3524 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3525 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3528 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3529 | struct nfs_fsinfo *info) |
| 3530 | { |
| 3531 | int error; |
| 3532 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3533 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3534 | |
| 3535 | error = nfs4_server_capabilities(server, mntfh); |
| 3536 | if (error < 0) { |
| 3537 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3538 | return error; |
| 3539 | } |
| 3540 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3541 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3542 | if (IS_ERR(label)) |
| 3543 | return PTR_ERR(label); |
| 3544 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3545 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3546 | if (error < 0) { |
| 3547 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3548 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3552 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3553 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3554 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3555 | err_free_label: |
| 3556 | nfs4_label_free(label); |
| 3557 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3558 | return error; |
| 3559 | } |
| 3560 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3561 | /* |
| 3562 | * Get locations and (maybe) other attributes of a referral. |
| 3563 | * Note that we'll actually follow the referral later when |
| 3564 | * we detect fsid mismatch in inode revalidation |
| 3565 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3566 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3567 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3568 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3569 | { |
| 3570 | int status = -ENOMEM; |
| 3571 | struct page *page = NULL; |
| 3572 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3573 | |
| 3574 | page = alloc_page(GFP_KERNEL); |
| 3575 | if (page == NULL) |
| 3576 | goto out; |
| 3577 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3578 | if (locations == NULL) |
| 3579 | goto out; |
| 3580 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3581 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3582 | if (status != 0) |
| 3583 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3584 | |
| 3585 | /* |
| 3586 | * If the fsid didn't change, this is a migration event, not a |
| 3587 | * referral. Cause us to drop into the exception handler, which |
| 3588 | * will kick off migration recovery. |
| 3589 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3590 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3591 | dprintk("%s: server did not return a different fsid for" |
| 3592 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3593 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3594 | goto out; |
| 3595 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3596 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3597 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3598 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3599 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3600 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3601 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3602 | out: |
| 3603 | if (page) |
| 3604 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3605 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3606 | return status; |
| 3607 | } |
| 3608 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3609 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3610 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | { |
| 3612 | struct nfs4_getattr_arg args = { |
| 3613 | .fh = fhandle, |
| 3614 | .bitmask = server->attr_bitmask, |
| 3615 | }; |
| 3616 | struct nfs4_getattr_res res = { |
| 3617 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3618 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | .server = server, |
| 3620 | }; |
| 3621 | struct rpc_message msg = { |
| 3622 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3623 | .rpc_argp = &args, |
| 3624 | .rpc_resp = &res, |
| 3625 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3626 | |
| 3627 | args.bitmask = nfs4_bitmask(server, label); |
| 3628 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3629 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3630 | 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] | 3631 | } |
| 3632 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3633 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3634 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | { |
| 3636 | struct nfs4_exception exception = { }; |
| 3637 | int err; |
| 3638 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3639 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3640 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3641 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | &exception); |
| 3643 | } while (exception.retry); |
| 3644 | return err; |
| 3645 | } |
| 3646 | |
| 3647 | /* |
| 3648 | * The file is not closed if it is opened due to the a request to change |
| 3649 | * the size of the file. The open call will not be needed once the |
| 3650 | * VFS layer lookup-intents are implemented. |
| 3651 | * |
| 3652 | * Close is called when the inode is destroyed. |
| 3653 | * If we haven't opened the file for O_WRONLY, we |
| 3654 | * need to in the size_change case to obtain a stateid. |
| 3655 | * |
| 3656 | * Got race? |
| 3657 | * Because OPEN is always done by name in nfsv4, it is |
| 3658 | * possible that we opened a different file by the same |
| 3659 | * name. We can recognize this race condition, but we |
| 3660 | * can't do anything about it besides returning an error. |
| 3661 | * |
| 3662 | * This will be fixed with VFS changes (lookup-intent). |
| 3663 | */ |
| 3664 | static int |
| 3665 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3666 | struct iattr *sattr) |
| 3667 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3668 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3669 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3670 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3671 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | int status; |
| 3673 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3674 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3675 | sattr->ia_valid & ATTR_SIZE && |
| 3676 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3677 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3678 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3679 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3681 | /* Deal with open(O_TRUNC) */ |
| 3682 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3683 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3684 | |
| 3685 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3686 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3687 | return 0; |
| 3688 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3689 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3690 | if (sattr->ia_valid & ATTR_FILE) { |
| 3691 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3692 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3693 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3694 | if (ctx) { |
| 3695 | cred = ctx->cred; |
| 3696 | state = ctx->state; |
| 3697 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3698 | } |
| 3699 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3700 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3701 | if (IS_ERR(label)) |
| 3702 | return PTR_ERR(label); |
| 3703 | |
| 3704 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3705 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3706 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3707 | nfs_setsecurity(inode, fattr, label); |
| 3708 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3709 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | return status; |
| 3711 | } |
| 3712 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3713 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3714 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3715 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3716 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3717 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3718 | int status; |
| 3719 | struct nfs4_lookup_arg args = { |
| 3720 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3721 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3722 | .name = name, |
| 3723 | }; |
| 3724 | struct nfs4_lookup_res res = { |
| 3725 | .server = server, |
| 3726 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3727 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3728 | .fh = fhandle, |
| 3729 | }; |
| 3730 | struct rpc_message msg = { |
| 3731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3732 | .rpc_argp = &args, |
| 3733 | .rpc_resp = &res, |
| 3734 | }; |
| 3735 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3736 | args.bitmask = nfs4_bitmask(server, label); |
| 3737 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3738 | nfs_fattr_init(fattr); |
| 3739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3741 | 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] | 3742 | dprintk("NFS reply lookup: %d\n", status); |
| 3743 | return status; |
| 3744 | } |
| 3745 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3746 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3747 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3748 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3749 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3750 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3751 | fattr->nlink = 2; |
| 3752 | } |
| 3753 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3754 | 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] | 3755 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3756 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3757 | { |
| 3758 | struct nfs4_exception exception = { }; |
| 3759 | struct rpc_clnt *client = *clnt; |
| 3760 | int err; |
| 3761 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3762 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3763 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3764 | switch (err) { |
| 3765 | case -NFS4ERR_BADNAME: |
| 3766 | err = -ENOENT; |
| 3767 | goto out; |
| 3768 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3769 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3770 | if (err == -NFS4ERR_MOVED) |
| 3771 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3772 | goto out; |
| 3773 | case -NFS4ERR_WRONGSEC: |
| 3774 | err = -EPERM; |
| 3775 | if (client != *clnt) |
| 3776 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3777 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3778 | if (IS_ERR(client)) |
| 3779 | return PTR_ERR(client); |
| 3780 | |
| 3781 | exception.retry = 1; |
| 3782 | break; |
| 3783 | default: |
| 3784 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3785 | } |
| 3786 | } while (exception.retry); |
| 3787 | |
| 3788 | out: |
| 3789 | if (err == 0) |
| 3790 | *clnt = client; |
| 3791 | else if (client != *clnt) |
| 3792 | rpc_shutdown_client(client); |
| 3793 | |
| 3794 | return err; |
| 3795 | } |
| 3796 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3797 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3798 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3799 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3801 | int status; |
| 3802 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3803 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3804 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3805 | if (client != NFS_CLIENT(dir)) { |
| 3806 | rpc_shutdown_client(client); |
| 3807 | nfs_fixup_secinfo_attributes(fattr); |
| 3808 | } |
| 3809 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3812 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3813 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3814 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3815 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3816 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3817 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3818 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3819 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3820 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3821 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3822 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3823 | } |
| 3824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3826 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3827 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | struct nfs4_accessargs args = { |
| 3829 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3830 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3832 | struct nfs4_accessres res = { |
| 3833 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3834 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | struct rpc_message msg = { |
| 3836 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3837 | .rpc_argp = &args, |
| 3838 | .rpc_resp = &res, |
| 3839 | .rpc_cred = entry->cred, |
| 3840 | }; |
| 3841 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3842 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
| 3844 | /* |
| 3845 | * Determine which access bits we want to ask for... |
| 3846 | */ |
| 3847 | if (mode & MAY_READ) |
| 3848 | args.access |= NFS4_ACCESS_READ; |
| 3849 | if (S_ISDIR(inode->i_mode)) { |
| 3850 | if (mode & MAY_WRITE) |
| 3851 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3852 | if (mode & MAY_EXEC) |
| 3853 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3854 | } else { |
| 3855 | if (mode & MAY_WRITE) |
| 3856 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3857 | if (mode & MAY_EXEC) |
| 3858 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3859 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3860 | |
| 3861 | res.fattr = nfs_alloc_fattr(); |
| 3862 | if (res.fattr == NULL) |
| 3863 | return -ENOMEM; |
| 3864 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3865 | 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] | 3866 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3867 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3868 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3870 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | return status; |
| 3872 | } |
| 3873 | |
| 3874 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3875 | { |
| 3876 | struct nfs4_exception exception = { }; |
| 3877 | int err; |
| 3878 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3879 | err = _nfs4_proc_access(inode, entry); |
| 3880 | trace_nfs4_access(inode, err); |
| 3881 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | &exception); |
| 3883 | } while (exception.retry); |
| 3884 | return err; |
| 3885 | } |
| 3886 | |
| 3887 | /* |
| 3888 | * TODO: For the time being, we don't try to get any attributes |
| 3889 | * along with any of the zero-copy operations READ, READDIR, |
| 3890 | * READLINK, WRITE. |
| 3891 | * |
| 3892 | * In the case of the first three, we want to put the GETATTR |
| 3893 | * after the read-type operation -- this is because it is hard |
| 3894 | * to predict the length of a GETATTR response in v4, and thus |
| 3895 | * align the READ data correctly. This means that the GETATTR |
| 3896 | * may end up partially falling into the page cache, and we should |
| 3897 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3898 | * To do this efficiently, we need to know the total length |
| 3899 | * of data received, which doesn't seem to be available outside |
| 3900 | * of the RPC layer. |
| 3901 | * |
| 3902 | * In the case of WRITE, we also want to put the GETATTR after |
| 3903 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3904 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | * |
| 3906 | * Both of these changes to the XDR layer would in fact be quite |
| 3907 | * minor, but I decided to leave them for a subsequent patch. |
| 3908 | */ |
| 3909 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3910 | unsigned int pgbase, unsigned int pglen) |
| 3911 | { |
| 3912 | struct nfs4_readlink args = { |
| 3913 | .fh = NFS_FH(inode), |
| 3914 | .pgbase = pgbase, |
| 3915 | .pglen = pglen, |
| 3916 | .pages = &page, |
| 3917 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3918 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | struct rpc_message msg = { |
| 3920 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3921 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3922 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | }; |
| 3924 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3925 | 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] | 3926 | } |
| 3927 | |
| 3928 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3929 | unsigned int pgbase, unsigned int pglen) |
| 3930 | { |
| 3931 | struct nfs4_exception exception = { }; |
| 3932 | int err; |
| 3933 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3934 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3935 | trace_nfs4_readlink(inode, err); |
| 3936 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | &exception); |
| 3938 | } while (exception.retry); |
| 3939 | return err; |
| 3940 | } |
| 3941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3943 | * 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] | 3944 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | static int |
| 3946 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3947 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3949 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3950 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | int status = 0; |
| 3953 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3954 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3955 | if (IS_ERR(ctx)) |
| 3956 | return PTR_ERR(ctx); |
| 3957 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3958 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3959 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3960 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3961 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | if (IS_ERR(state)) { |
| 3963 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3964 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3967 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3968 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | return status; |
| 3970 | } |
| 3971 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3972 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3974 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3975 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3977 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3979 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3980 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3981 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3984 | .rpc_argp = &args, |
| 3985 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3987 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3988 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3989 | 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] | 3990 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3991 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | return status; |
| 3993 | } |
| 3994 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3995 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | { |
| 3997 | struct nfs4_exception exception = { }; |
| 3998 | int err; |
| 3999 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4000 | err = _nfs4_proc_remove(dir, name); |
| 4001 | trace_nfs4_remove(dir, name, err); |
| 4002 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | &exception); |
| 4004 | } while (exception.retry); |
| 4005 | return err; |
| 4006 | } |
| 4007 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4008 | 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] | 4009 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4010 | struct nfs_server *server = NFS_SERVER(dir); |
| 4011 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4012 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4014 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4016 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4017 | |
| 4018 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4021 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4022 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4023 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4024 | &data->args.seq_args, |
| 4025 | &data->res.seq_res, |
| 4026 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4029 | 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] | 4030 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4031 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4032 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4033 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4034 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4035 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4036 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4037 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4038 | return 0; |
| 4039 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4040 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4043 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4044 | { |
| 4045 | struct nfs_server *server = NFS_SERVER(dir); |
| 4046 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4047 | struct nfs_renameres *res = msg->rpc_resp; |
| 4048 | |
| 4049 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4050 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4051 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4052 | } |
| 4053 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4054 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4055 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4056 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4057 | &data->args.seq_args, |
| 4058 | &data->res.seq_res, |
| 4059 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4063 | struct inode *new_dir) |
| 4064 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4065 | struct nfs_renamedata *data = task->tk_calldata; |
| 4066 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4067 | |
| 4068 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4069 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4070 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4071 | return 0; |
| 4072 | |
| 4073 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4074 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4075 | return 1; |
| 4076 | } |
| 4077 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4078 | 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] | 4079 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4080 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | struct nfs4_link_arg arg = { |
| 4082 | .fh = NFS_FH(inode), |
| 4083 | .dir_fh = NFS_FH(dir), |
| 4084 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4085 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4087 | struct nfs4_link_res res = { |
| 4088 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4089 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4090 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | struct rpc_message msg = { |
| 4092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4093 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4094 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4096 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4098 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4099 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4100 | goto out; |
| 4101 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4102 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4103 | if (IS_ERR(res.label)) { |
| 4104 | status = PTR_ERR(res.label); |
| 4105 | goto out; |
| 4106 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4107 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4108 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4109 | 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] | 4110 | if (!status) { |
| 4111 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4112 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4113 | if (!status) |
| 4114 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4115 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4116 | |
| 4117 | |
| 4118 | nfs4_label_free(res.label); |
| 4119 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4120 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4121 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | return status; |
| 4123 | } |
| 4124 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4125 | 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] | 4126 | { |
| 4127 | struct nfs4_exception exception = { }; |
| 4128 | int err; |
| 4129 | do { |
| 4130 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4131 | _nfs4_proc_link(inode, dir, name), |
| 4132 | &exception); |
| 4133 | } while (exception.retry); |
| 4134 | return err; |
| 4135 | } |
| 4136 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4137 | struct nfs4_createdata { |
| 4138 | struct rpc_message msg; |
| 4139 | struct nfs4_create_arg arg; |
| 4140 | struct nfs4_create_res res; |
| 4141 | struct nfs_fh fh; |
| 4142 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4143 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4144 | }; |
| 4145 | |
| 4146 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4147 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4148 | { |
| 4149 | struct nfs4_createdata *data; |
| 4150 | |
| 4151 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4152 | if (data != NULL) { |
| 4153 | struct nfs_server *server = NFS_SERVER(dir); |
| 4154 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4155 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4156 | if (IS_ERR(data->label)) |
| 4157 | goto out_free; |
| 4158 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4159 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4160 | data->msg.rpc_argp = &data->arg; |
| 4161 | data->msg.rpc_resp = &data->res; |
| 4162 | data->arg.dir_fh = NFS_FH(dir); |
| 4163 | data->arg.server = server; |
| 4164 | data->arg.name = name; |
| 4165 | data->arg.attrs = sattr; |
| 4166 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4167 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4168 | data->res.server = server; |
| 4169 | data->res.fh = &data->fh; |
| 4170 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4171 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4172 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4173 | } |
| 4174 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4175 | out_free: |
| 4176 | kfree(data); |
| 4177 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4181 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4182 | 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] | 4183 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4184 | if (status == 0) { |
| 4185 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4186 | 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] | 4187 | } |
| 4188 | return status; |
| 4189 | } |
| 4190 | |
| 4191 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4192 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4193 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4194 | kfree(data); |
| 4195 | } |
| 4196 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4197 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4198 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4199 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4201 | struct nfs4_createdata *data; |
| 4202 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4204 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4205 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4206 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4207 | status = -ENOMEM; |
| 4208 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4209 | if (data == NULL) |
| 4210 | goto out; |
| 4211 | |
| 4212 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4213 | data->arg.u.symlink.pages = &page; |
| 4214 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4215 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4217 | status = nfs4_do_create(dir, dentry, data); |
| 4218 | |
| 4219 | nfs4_free_createdata(data); |
| 4220 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | return status; |
| 4222 | } |
| 4223 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4224 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4225 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | { |
| 4227 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4228 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4230 | |
| 4231 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4234 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4235 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4236 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | &exception); |
| 4238 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4239 | |
| 4240 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | return err; |
| 4242 | } |
| 4243 | |
| 4244 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4245 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4247 | struct nfs4_createdata *data; |
| 4248 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4250 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4251 | if (data == NULL) |
| 4252 | goto out; |
| 4253 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4254 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4255 | status = nfs4_do_create(dir, dentry, data); |
| 4256 | |
| 4257 | nfs4_free_createdata(data); |
| 4258 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | return status; |
| 4260 | } |
| 4261 | |
| 4262 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4263 | struct iattr *sattr) |
| 4264 | { |
| 4265 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4266 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4268 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4269 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4270 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4271 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4273 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4274 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4275 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | &exception); |
| 4277 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4278 | nfs4_label_release_security(label); |
| 4279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | return err; |
| 4281 | } |
| 4282 | |
| 4283 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4284 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4286 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | struct nfs4_readdir_arg args = { |
| 4288 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4289 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | .pgbase = 0, |
| 4291 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4292 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4293 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | }; |
| 4295 | struct nfs4_readdir_res res; |
| 4296 | struct rpc_message msg = { |
| 4297 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4298 | .rpc_argp = &args, |
| 4299 | .rpc_resp = &res, |
| 4300 | .rpc_cred = cred, |
| 4301 | }; |
| 4302 | int status; |
| 4303 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4304 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4305 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4306 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4307 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4309 | 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] | 4310 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4311 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4312 | status += args.pgbase; |
| 4313 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4314 | |
| 4315 | nfs_invalidate_atime(dir); |
| 4316 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4317 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | return status; |
| 4319 | } |
| 4320 | |
| 4321 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4322 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | { |
| 4324 | struct nfs4_exception exception = { }; |
| 4325 | int err; |
| 4326 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4327 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4328 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4329 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4330 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | &exception); |
| 4332 | } while (exception.retry); |
| 4333 | return err; |
| 4334 | } |
| 4335 | |
| 4336 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4337 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4339 | struct nfs4_createdata *data; |
| 4340 | int mode = sattr->ia_mode; |
| 4341 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4343 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4344 | if (data == NULL) |
| 4345 | goto out; |
| 4346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4348 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4350 | data->arg.ftype = NF4BLK; |
| 4351 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4352 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | } |
| 4354 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4355 | data->arg.ftype = NF4CHR; |
| 4356 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4357 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4358 | } else if (!S_ISSOCK(mode)) { |
| 4359 | status = -EINVAL; |
| 4360 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4362 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4363 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4364 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4365 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4366 | nfs4_free_createdata(data); |
| 4367 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | return status; |
| 4369 | } |
| 4370 | |
| 4371 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4372 | struct iattr *sattr, dev_t rdev) |
| 4373 | { |
| 4374 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4375 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4377 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4378 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4379 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4380 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4382 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4383 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4384 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | &exception); |
| 4386 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4387 | |
| 4388 | nfs4_label_release_security(label); |
| 4389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | return err; |
| 4391 | } |
| 4392 | |
| 4393 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4394 | struct nfs_fsstat *fsstat) |
| 4395 | { |
| 4396 | struct nfs4_statfs_arg args = { |
| 4397 | .fh = fhandle, |
| 4398 | .bitmask = server->attr_bitmask, |
| 4399 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4400 | struct nfs4_statfs_res res = { |
| 4401 | .fsstat = fsstat, |
| 4402 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | struct rpc_message msg = { |
| 4404 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4405 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4406 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | }; |
| 4408 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4409 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4410 | 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] | 4411 | } |
| 4412 | |
| 4413 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4414 | { |
| 4415 | struct nfs4_exception exception = { }; |
| 4416 | int err; |
| 4417 | do { |
| 4418 | err = nfs4_handle_exception(server, |
| 4419 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4420 | &exception); |
| 4421 | } while (exception.retry); |
| 4422 | return err; |
| 4423 | } |
| 4424 | |
| 4425 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4426 | struct nfs_fsinfo *fsinfo) |
| 4427 | { |
| 4428 | struct nfs4_fsinfo_arg args = { |
| 4429 | .fh = fhandle, |
| 4430 | .bitmask = server->attr_bitmask, |
| 4431 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4432 | struct nfs4_fsinfo_res res = { |
| 4433 | .fsinfo = fsinfo, |
| 4434 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | struct rpc_message msg = { |
| 4436 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4437 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4438 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | }; |
| 4440 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4441 | 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] | 4442 | } |
| 4443 | |
| 4444 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4445 | { |
| 4446 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4447 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | int err; |
| 4449 | |
| 4450 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4451 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4452 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4453 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4454 | nfs4_set_lease_period(server->nfs_client, |
| 4455 | fsinfo->lease_time * HZ, |
| 4456 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4457 | break; |
| 4458 | } |
| 4459 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | } while (exception.retry); |
| 4461 | return err; |
| 4462 | } |
| 4463 | |
| 4464 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4465 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4466 | int error; |
| 4467 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4468 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4469 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4470 | if (error == 0) { |
| 4471 | /* block layout checks this! */ |
| 4472 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4473 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4474 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4475 | |
| 4476 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4480 | struct nfs_pathconf *pathconf) |
| 4481 | { |
| 4482 | struct nfs4_pathconf_arg args = { |
| 4483 | .fh = fhandle, |
| 4484 | .bitmask = server->attr_bitmask, |
| 4485 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4486 | struct nfs4_pathconf_res res = { |
| 4487 | .pathconf = pathconf, |
| 4488 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | struct rpc_message msg = { |
| 4490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4491 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4492 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | }; |
| 4494 | |
| 4495 | /* None of the pathconf attributes are mandatory to implement */ |
| 4496 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4497 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4498 | return 0; |
| 4499 | } |
| 4500 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4501 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4502 | 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] | 4503 | } |
| 4504 | |
| 4505 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4506 | struct nfs_pathconf *pathconf) |
| 4507 | { |
| 4508 | struct nfs4_exception exception = { }; |
| 4509 | int err; |
| 4510 | |
| 4511 | do { |
| 4512 | err = nfs4_handle_exception(server, |
| 4513 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4514 | &exception); |
| 4515 | } while (exception.retry); |
| 4516 | return err; |
| 4517 | } |
| 4518 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4519 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4520 | const struct nfs_open_context *ctx, |
| 4521 | const struct nfs_lock_context *l_ctx, |
| 4522 | fmode_t fmode) |
| 4523 | { |
| 4524 | const struct nfs_lockowner *lockowner = NULL; |
| 4525 | |
| 4526 | if (l_ctx != NULL) |
| 4527 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4528 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4529 | } |
| 4530 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4531 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4532 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4533 | const struct nfs_open_context *ctx, |
| 4534 | const struct nfs_lock_context *l_ctx, |
| 4535 | fmode_t fmode) |
| 4536 | { |
| 4537 | nfs4_stateid current_stateid; |
| 4538 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4539 | /* If the current stateid represents a lost lock, then exit */ |
| 4540 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4541 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4542 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4543 | } |
| 4544 | |
| 4545 | static bool nfs4_error_stateid_expired(int err) |
| 4546 | { |
| 4547 | switch (err) { |
| 4548 | case -NFS4ERR_DELEG_REVOKED: |
| 4549 | case -NFS4ERR_ADMIN_REVOKED: |
| 4550 | case -NFS4ERR_BAD_STATEID: |
| 4551 | case -NFS4ERR_STALE_STATEID: |
| 4552 | case -NFS4ERR_OLD_STATEID: |
| 4553 | case -NFS4ERR_OPENMODE: |
| 4554 | case -NFS4ERR_EXPIRED: |
| 4555 | return true; |
| 4556 | } |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4560 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4561 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4562 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4563 | } |
| 4564 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4565 | 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] | 4566 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4567 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4569 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4570 | if (task->tk_status < 0) { |
| 4571 | struct nfs4_exception exception = { |
| 4572 | .inode = hdr->inode, |
| 4573 | .state = hdr->args.context->state, |
| 4574 | .stateid = &hdr->args.stateid, |
| 4575 | }; |
| 4576 | task->tk_status = nfs4_async_handle_exception(task, |
| 4577 | server, task->tk_status, &exception); |
| 4578 | if (exception.retry) { |
| 4579 | rpc_restart_call_prepare(task); |
| 4580 | return -EAGAIN; |
| 4581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4583 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4584 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4586 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4587 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4590 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4591 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4592 | { |
| 4593 | |
| 4594 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4595 | nfs4_stateid_is_current(&args->stateid, |
| 4596 | args->context, |
| 4597 | args->lock_context, |
| 4598 | FMODE_READ)) |
| 4599 | return false; |
| 4600 | rpc_restart_call_prepare(task); |
| 4601 | return true; |
| 4602 | } |
| 4603 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4604 | 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] | 4605 | { |
| 4606 | |
| 4607 | dprintk("--> %s\n", __func__); |
| 4608 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4609 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4610 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4611 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4612 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4613 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4614 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4617 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4618 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4620 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4621 | if (!hdr->pgio_done_cb) |
| 4622 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4623 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4624 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | } |
| 4626 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4627 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4628 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4629 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4630 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4631 | &hdr->args.seq_args, |
| 4632 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4633 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4634 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4635 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4636 | hdr->args.lock_context, |
| 4637 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4638 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4639 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4640 | return -EIO; |
| 4641 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4644 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4645 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4647 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4648 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4649 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4650 | if (task->tk_status < 0) { |
| 4651 | struct nfs4_exception exception = { |
| 4652 | .inode = hdr->inode, |
| 4653 | .state = hdr->args.context->state, |
| 4654 | .stateid = &hdr->args.stateid, |
| 4655 | }; |
| 4656 | task->tk_status = nfs4_async_handle_exception(task, |
| 4657 | NFS_SERVER(inode), task->tk_status, |
| 4658 | &exception); |
| 4659 | if (exception.retry) { |
| 4660 | rpc_restart_call_prepare(task); |
| 4661 | return -EAGAIN; |
| 4662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4664 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4665 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4666 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4667 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4668 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4671 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4672 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4673 | { |
| 4674 | |
| 4675 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4676 | nfs4_stateid_is_current(&args->stateid, |
| 4677 | args->context, |
| 4678 | args->lock_context, |
| 4679 | FMODE_WRITE)) |
| 4680 | return false; |
| 4681 | rpc_restart_call_prepare(task); |
| 4682 | return true; |
| 4683 | } |
| 4684 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4685 | 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] | 4686 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4687 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4688 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4689 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4690 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4691 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4692 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4695 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4696 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4697 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4698 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4699 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4700 | return false; |
| 4701 | /* Otherwise, request attributes if and only if we don't hold |
| 4702 | * a delegation |
| 4703 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4704 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4705 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4706 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4707 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4708 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4711 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4712 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4713 | hdr->args.bitmask = NULL; |
| 4714 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4715 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4716 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4717 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4718 | if (!hdr->pgio_done_cb) |
| 4719 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4720 | hdr->res.server = server; |
| 4721 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4723 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4724 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4727 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4728 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4729 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4730 | &data->args.seq_args, |
| 4731 | &data->res.seq_res, |
| 4732 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4735 | 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] | 4736 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4738 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4739 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4740 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4741 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4742 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4743 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4745 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4748 | 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] | 4749 | { |
| 4750 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4751 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4752 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4755 | 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] | 4756 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4757 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4758 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4759 | if (data->commit_done_cb == NULL) |
| 4760 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4761 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4762 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4763 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4766 | struct nfs4_renewdata { |
| 4767 | struct nfs_client *client; |
| 4768 | unsigned long timestamp; |
| 4769 | }; |
| 4770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | /* |
| 4772 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4773 | * standalone procedure for queueing an asynchronous RENEW. |
| 4774 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4775 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4776 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4777 | struct nfs4_renewdata *data = calldata; |
| 4778 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4779 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4780 | if (atomic_read(&clp->cl_count) > 1) |
| 4781 | nfs4_schedule_state_renewal(clp); |
| 4782 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4783 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4784 | } |
| 4785 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4786 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4788 | struct nfs4_renewdata *data = calldata; |
| 4789 | struct nfs_client *clp = data->client; |
| 4790 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4792 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4793 | switch (task->tk_status) { |
| 4794 | case 0: |
| 4795 | break; |
| 4796 | case -NFS4ERR_LEASE_MOVED: |
| 4797 | nfs4_schedule_lease_moved_recovery(clp); |
| 4798 | break; |
| 4799 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4800 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4801 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4802 | return; |
| 4803 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4804 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4805 | return; |
| 4806 | } |
| 4807 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4809 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4812 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4813 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4814 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4815 | }; |
| 4816 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4817 | 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] | 4818 | { |
| 4819 | struct rpc_message msg = { |
| 4820 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4821 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4822 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4824 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4826 | if (renew_flags == 0) |
| 4827 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4828 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4829 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4830 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4831 | if (data == NULL) |
| 4832 | return -ENOMEM; |
| 4833 | data->client = clp; |
| 4834 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4835 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4836 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4839 | 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] | 4840 | { |
| 4841 | struct rpc_message msg = { |
| 4842 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4843 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4844 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | }; |
| 4846 | unsigned long now = jiffies; |
| 4847 | int status; |
| 4848 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4849 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | if (status < 0) |
| 4851 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4852 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | return 0; |
| 4854 | } |
| 4855 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4856 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4857 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4858 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4861 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4862 | * 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] | 4863 | * the stack. |
| 4864 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4865 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4866 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4867 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4868 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4869 | { |
| 4870 | struct page *newpage, **spages; |
| 4871 | int rc = 0; |
| 4872 | size_t len; |
| 4873 | spages = pages; |
| 4874 | |
| 4875 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4876 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4877 | newpage = alloc_page(GFP_KERNEL); |
| 4878 | |
| 4879 | if (newpage == NULL) |
| 4880 | goto unwind; |
| 4881 | memcpy(page_address(newpage), buf, len); |
| 4882 | buf += len; |
| 4883 | buflen -= len; |
| 4884 | *pages++ = newpage; |
| 4885 | rc++; |
| 4886 | } while (buflen != 0); |
| 4887 | |
| 4888 | return rc; |
| 4889 | |
| 4890 | unwind: |
| 4891 | for(; rc > 0; rc--) |
| 4892 | __free_page(spages[rc-1]); |
| 4893 | return -ENOMEM; |
| 4894 | } |
| 4895 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4896 | struct nfs4_cached_acl { |
| 4897 | int cached; |
| 4898 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4899 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4900 | }; |
| 4901 | |
| 4902 | 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] | 4903 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4904 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4905 | |
| 4906 | spin_lock(&inode->i_lock); |
| 4907 | kfree(nfsi->nfs4_acl); |
| 4908 | nfsi->nfs4_acl = acl; |
| 4909 | spin_unlock(&inode->i_lock); |
| 4910 | } |
| 4911 | |
| 4912 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4913 | { |
| 4914 | nfs4_set_cached_acl(inode, NULL); |
| 4915 | } |
| 4916 | |
| 4917 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4918 | { |
| 4919 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4920 | struct nfs4_cached_acl *acl; |
| 4921 | int ret = -ENOENT; |
| 4922 | |
| 4923 | spin_lock(&inode->i_lock); |
| 4924 | acl = nfsi->nfs4_acl; |
| 4925 | if (acl == NULL) |
| 4926 | goto out; |
| 4927 | if (buf == NULL) /* user is just asking for length */ |
| 4928 | goto out_len; |
| 4929 | if (acl->cached == 0) |
| 4930 | goto out; |
| 4931 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4932 | if (acl->len > buflen) |
| 4933 | goto out; |
| 4934 | memcpy(buf, acl->data, acl->len); |
| 4935 | out_len: |
| 4936 | ret = acl->len; |
| 4937 | out: |
| 4938 | spin_unlock(&inode->i_lock); |
| 4939 | return ret; |
| 4940 | } |
| 4941 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4942 | 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] | 4943 | { |
| 4944 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4945 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4946 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4947 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4948 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4949 | if (acl == NULL) |
| 4950 | goto out; |
| 4951 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4952 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4953 | } else { |
| 4954 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4955 | if (acl == NULL) |
| 4956 | goto out; |
| 4957 | acl->cached = 0; |
| 4958 | } |
| 4959 | acl->len = acl_len; |
| 4960 | out: |
| 4961 | nfs4_set_cached_acl(inode, acl); |
| 4962 | } |
| 4963 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4964 | /* |
| 4965 | * The getxattr API returns the required buffer length when called with a |
| 4966 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4967 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4968 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4969 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4970 | * the cache. If not so, we throw away the page, and cache the required |
| 4971 | * length. The next getxattr call will then produce another round trip to |
| 4972 | * the server, this time with the input buf of the required size. |
| 4973 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4974 | 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] | 4975 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4976 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4977 | struct nfs_getaclargs args = { |
| 4978 | .fh = NFS_FH(inode), |
| 4979 | .acl_pages = pages, |
| 4980 | .acl_len = buflen, |
| 4981 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4982 | struct nfs_getaclres res = { |
| 4983 | .acl_len = buflen, |
| 4984 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4985 | struct rpc_message msg = { |
| 4986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4987 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4988 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4989 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4990 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4991 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4992 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4993 | /* As long as we're doing a round trip to the server anyway, |
| 4994 | * let's be prepared for a page of acl data. */ |
| 4995 | if (npages == 0) |
| 4996 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4997 | if (npages > ARRAY_SIZE(pages)) |
| 4998 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4999 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5000 | for (i = 0; i < npages; i++) { |
| 5001 | pages[i] = alloc_page(GFP_KERNEL); |
| 5002 | if (!pages[i]) |
| 5003 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5004 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5005 | |
| 5006 | /* for decoding across pages */ |
| 5007 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5008 | if (!res.acl_scratch) |
| 5009 | goto out_free; |
| 5010 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5011 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5012 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5013 | 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] | 5014 | __func__, buf, buflen, npages, args.acl_len); |
| 5015 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5016 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5017 | if (ret) |
| 5018 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5019 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5020 | /* Handle the case where the passed-in buffer is too short */ |
| 5021 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5022 | /* Did the user only issue a request for the acl length? */ |
| 5023 | if (buf == NULL) |
| 5024 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5025 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5026 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5027 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5028 | 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] | 5029 | if (buf) { |
| 5030 | if (res.acl_len > buflen) { |
| 5031 | ret = -ERANGE; |
| 5032 | goto out_free; |
| 5033 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5034 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5035 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5036 | out_ok: |
| 5037 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5038 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5039 | for (i = 0; i < npages; i++) |
| 5040 | if (pages[i]) |
| 5041 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5042 | if (res.acl_scratch) |
| 5043 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5044 | return ret; |
| 5045 | } |
| 5046 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5047 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5048 | { |
| 5049 | struct nfs4_exception exception = { }; |
| 5050 | ssize_t ret; |
| 5051 | do { |
| 5052 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5053 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5054 | if (ret >= 0) |
| 5055 | break; |
| 5056 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5057 | } while (exception.retry); |
| 5058 | return ret; |
| 5059 | } |
| 5060 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5061 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5062 | { |
| 5063 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5064 | int ret; |
| 5065 | |
| 5066 | if (!nfs4_server_supports_acls(server)) |
| 5067 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5068 | ret = nfs_revalidate_inode(server, inode); |
| 5069 | if (ret < 0) |
| 5070 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5071 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5072 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5073 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5074 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5075 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5076 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5077 | return ret; |
| 5078 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5081 | 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] | 5082 | { |
| 5083 | struct nfs_server *server = NFS_SERVER(inode); |
| 5084 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5085 | struct nfs_setaclargs arg = { |
| 5086 | .fh = NFS_FH(inode), |
| 5087 | .acl_pages = pages, |
| 5088 | .acl_len = buflen, |
| 5089 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5090 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5091 | struct rpc_message msg = { |
| 5092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5093 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5094 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5095 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5096 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5097 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5098 | |
| 5099 | if (!nfs4_server_supports_acls(server)) |
| 5100 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5101 | if (npages > ARRAY_SIZE(pages)) |
| 5102 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5103 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5104 | if (i < 0) |
| 5105 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5106 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5107 | 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] | 5108 | |
| 5109 | /* |
| 5110 | * Free each page after tx, so the only ref left is |
| 5111 | * held by the network stack |
| 5112 | */ |
| 5113 | for (; i > 0; i--) |
| 5114 | put_page(pages[i-1]); |
| 5115 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5116 | /* |
| 5117 | * Acl update can result in inode attribute update. |
| 5118 | * so mark the attribute cache invalid. |
| 5119 | */ |
| 5120 | spin_lock(&inode->i_lock); |
| 5121 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5122 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5123 | nfs_access_zap_cache(inode); |
| 5124 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5125 | return ret; |
| 5126 | } |
| 5127 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5128 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5129 | { |
| 5130 | struct nfs4_exception exception = { }; |
| 5131 | int err; |
| 5132 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5133 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5134 | trace_nfs4_set_acl(inode, err); |
| 5135 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5136 | &exception); |
| 5137 | } while (exception.retry); |
| 5138 | return err; |
| 5139 | } |
| 5140 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5141 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5142 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5143 | size_t buflen) |
| 5144 | { |
| 5145 | struct nfs_server *server = NFS_SERVER(inode); |
| 5146 | struct nfs_fattr fattr; |
| 5147 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5148 | |
| 5149 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5150 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5151 | .fh = NFS_FH(inode), |
| 5152 | .bitmask = bitmask, |
| 5153 | }; |
| 5154 | struct nfs4_getattr_res res = { |
| 5155 | .fattr = &fattr, |
| 5156 | .label = &label, |
| 5157 | .server = server, |
| 5158 | }; |
| 5159 | struct rpc_message msg = { |
| 5160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5161 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5162 | .rpc_resp = &res, |
| 5163 | }; |
| 5164 | int ret; |
| 5165 | |
| 5166 | nfs_fattr_init(&fattr); |
| 5167 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5168 | 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] | 5169 | if (ret) |
| 5170 | return ret; |
| 5171 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5172 | return -ENOENT; |
| 5173 | if (buflen < label.len) |
| 5174 | return -ERANGE; |
| 5175 | return 0; |
| 5176 | } |
| 5177 | |
| 5178 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5179 | size_t buflen) |
| 5180 | { |
| 5181 | struct nfs4_exception exception = { }; |
| 5182 | int err; |
| 5183 | |
| 5184 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5185 | return -EOPNOTSUPP; |
| 5186 | |
| 5187 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5188 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5189 | trace_nfs4_get_security_label(inode, err); |
| 5190 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5191 | &exception); |
| 5192 | } while (exception.retry); |
| 5193 | return err; |
| 5194 | } |
| 5195 | |
| 5196 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5197 | struct nfs4_label *ilabel, |
| 5198 | struct nfs_fattr *fattr, |
| 5199 | struct nfs4_label *olabel) |
| 5200 | { |
| 5201 | |
| 5202 | struct iattr sattr = {0}; |
| 5203 | struct nfs_server *server = NFS_SERVER(inode); |
| 5204 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5205 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5206 | .fh = NFS_FH(inode), |
| 5207 | .iap = &sattr, |
| 5208 | .server = server, |
| 5209 | .bitmask = bitmask, |
| 5210 | .label = ilabel, |
| 5211 | }; |
| 5212 | struct nfs_setattrres res = { |
| 5213 | .fattr = fattr, |
| 5214 | .label = olabel, |
| 5215 | .server = server, |
| 5216 | }; |
| 5217 | struct rpc_message msg = { |
| 5218 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5219 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5220 | .rpc_resp = &res, |
| 5221 | }; |
| 5222 | int status; |
| 5223 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5224 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5225 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5226 | 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] | 5227 | if (status) |
| 5228 | dprintk("%s failed: %d\n", __func__, status); |
| 5229 | |
| 5230 | return status; |
| 5231 | } |
| 5232 | |
| 5233 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5234 | struct nfs4_label *ilabel, |
| 5235 | struct nfs_fattr *fattr, |
| 5236 | struct nfs4_label *olabel) |
| 5237 | { |
| 5238 | struct nfs4_exception exception = { }; |
| 5239 | int err; |
| 5240 | |
| 5241 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5242 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5243 | fattr, olabel); |
| 5244 | trace_nfs4_set_security_label(inode, err); |
| 5245 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5246 | &exception); |
| 5247 | } while (exception.retry); |
| 5248 | return err; |
| 5249 | } |
| 5250 | |
| 5251 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5252 | 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] | 5253 | { |
| 5254 | struct nfs4_label ilabel, *olabel = NULL; |
| 5255 | struct nfs_fattr fattr; |
| 5256 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5257 | int status; |
| 5258 | |
| 5259 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5260 | return -EOPNOTSUPP; |
| 5261 | |
| 5262 | nfs_fattr_init(&fattr); |
| 5263 | |
| 5264 | ilabel.pi = 0; |
| 5265 | ilabel.lfs = 0; |
| 5266 | ilabel.label = (char *)buf; |
| 5267 | ilabel.len = buflen; |
| 5268 | |
| 5269 | cred = rpc_lookup_cred(); |
| 5270 | if (IS_ERR(cred)) |
| 5271 | return PTR_ERR(cred); |
| 5272 | |
| 5273 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5274 | if (IS_ERR(olabel)) { |
| 5275 | status = -PTR_ERR(olabel); |
| 5276 | goto out; |
| 5277 | } |
| 5278 | |
| 5279 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5280 | if (status == 0) |
| 5281 | nfs_setsecurity(inode, &fattr, olabel); |
| 5282 | |
| 5283 | nfs4_label_free(olabel); |
| 5284 | out: |
| 5285 | put_rpccred(cred); |
| 5286 | return status; |
| 5287 | } |
| 5288 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5289 | |
| 5290 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5291 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5292 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5293 | { |
| 5294 | __be32 verf[2]; |
| 5295 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5296 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5297 | /* An impossible timestamp guarantees this value |
| 5298 | * will never match a generated boot time. */ |
| 5299 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5300 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5301 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5302 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5303 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5304 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5305 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5306 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5307 | } |
| 5308 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5309 | static int |
| 5310 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5311 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5312 | size_t len; |
| 5313 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5314 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5315 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5316 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5317 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5318 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5319 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5320 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5321 | 1 + |
| 5322 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5323 | 1; |
| 5324 | rcu_read_unlock(); |
| 5325 | |
| 5326 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5327 | return -EINVAL; |
| 5328 | |
| 5329 | /* |
| 5330 | * Since this string is allocated at mount time, and held until the |
| 5331 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5332 | * about a memory-reclaim deadlock. |
| 5333 | */ |
| 5334 | str = kmalloc(len, GFP_KERNEL); |
| 5335 | if (!str) |
| 5336 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5337 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5338 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5339 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5340 | clp->cl_ipaddr, |
| 5341 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5342 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5343 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5344 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5345 | clp->cl_owner_id = str; |
| 5346 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5347 | } |
| 5348 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5349 | static int |
| 5350 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5351 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5352 | size_t len; |
| 5353 | char *str; |
| 5354 | |
| 5355 | len = 10 + 10 + 1 + 10 + 1 + |
| 5356 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5357 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5358 | |
| 5359 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5360 | return -EINVAL; |
| 5361 | |
| 5362 | /* |
| 5363 | * Since this string is allocated at mount time, and held until the |
| 5364 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5365 | * about a memory-reclaim deadlock. |
| 5366 | */ |
| 5367 | str = kmalloc(len, GFP_KERNEL); |
| 5368 | if (!str) |
| 5369 | return -ENOMEM; |
| 5370 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5371 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5372 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5373 | nfs4_client_id_uniquifier, |
| 5374 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5375 | clp->cl_owner_id = str; |
| 5376 | return 0; |
| 5377 | } |
| 5378 | |
| 5379 | static int |
| 5380 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5381 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5382 | size_t len; |
| 5383 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5384 | |
| 5385 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5386 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5387 | |
| 5388 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5389 | return nfs4_init_uniquifier_client_string(clp); |
| 5390 | |
| 5391 | len = 10 + 10 + 1 + 10 + 1 + |
| 5392 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5393 | |
| 5394 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5395 | return -EINVAL; |
| 5396 | |
| 5397 | /* |
| 5398 | * Since this string is allocated at mount time, and held until the |
| 5399 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5400 | * about a memory-reclaim deadlock. |
| 5401 | */ |
| 5402 | str = kmalloc(len, GFP_KERNEL); |
| 5403 | if (!str) |
| 5404 | return -ENOMEM; |
| 5405 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5406 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5407 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5408 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5409 | clp->cl_owner_id = str; |
| 5410 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5411 | } |
| 5412 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5413 | /* |
| 5414 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5415 | * services. Advertise one based on the address family of the |
| 5416 | * clientaddr. |
| 5417 | */ |
| 5418 | static unsigned int |
| 5419 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5420 | { |
| 5421 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5422 | return scnprintf(buf, len, "tcp6"); |
| 5423 | else |
| 5424 | return scnprintf(buf, len, "tcp"); |
| 5425 | } |
| 5426 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5427 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5428 | { |
| 5429 | struct nfs4_setclientid *sc = calldata; |
| 5430 | |
| 5431 | if (task->tk_status == 0) |
| 5432 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5433 | } |
| 5434 | |
| 5435 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5436 | .rpc_call_done = nfs4_setclientid_done, |
| 5437 | }; |
| 5438 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5439 | /** |
| 5440 | * nfs4_proc_setclientid - Negotiate client ID |
| 5441 | * @clp: state data structure |
| 5442 | * @program: RPC program for NFSv4 callback service |
| 5443 | * @port: IP port number for NFS4 callback service |
| 5444 | * @cred: RPC credential to use for this call |
| 5445 | * @res: where to place the result |
| 5446 | * |
| 5447 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5448 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5449 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5450 | unsigned short port, struct rpc_cred *cred, |
| 5451 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | { |
| 5453 | nfs4_verifier sc_verifier; |
| 5454 | struct nfs4_setclientid setclientid = { |
| 5455 | .sc_verifier = &sc_verifier, |
| 5456 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5457 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | }; |
| 5459 | struct rpc_message msg = { |
| 5460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5461 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5462 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5463 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5465 | struct rpc_task *task; |
| 5466 | struct rpc_task_setup task_setup_data = { |
| 5467 | .rpc_client = clp->cl_rpcclient, |
| 5468 | .rpc_message = &msg, |
| 5469 | .callback_ops = &nfs4_setclientid_ops, |
| 5470 | .callback_data = &setclientid, |
| 5471 | .flags = RPC_TASK_TIMEOUT, |
| 5472 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5473 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5475 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5476 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5477 | |
| 5478 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5479 | status = nfs4_init_uniform_client_string(clp); |
| 5480 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5481 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5482 | |
| 5483 | if (status) |
| 5484 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5485 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5486 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5487 | setclientid.sc_netid_len = |
| 5488 | nfs4_init_callback_netid(clp, |
| 5489 | setclientid.sc_netid, |
| 5490 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5491 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5492 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5494 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5495 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5496 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5497 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5498 | task = rpc_run_task(&task_setup_data); |
| 5499 | if (IS_ERR(task)) { |
| 5500 | status = PTR_ERR(task); |
| 5501 | goto out; |
| 5502 | } |
| 5503 | status = task->tk_status; |
| 5504 | if (setclientid.sc_cred) { |
| 5505 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5506 | put_rpccred(setclientid.sc_cred); |
| 5507 | } |
| 5508 | rpc_put_task(task); |
| 5509 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5510 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5511 | dprintk("NFS reply setclientid: %d\n", status); |
| 5512 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | } |
| 5514 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5515 | /** |
| 5516 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5517 | * @clp: state data structure |
| 5518 | * @res: result of a previous SETCLIENTID |
| 5519 | * @cred: RPC credential to use for this call |
| 5520 | * |
| 5521 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5522 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5523 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5524 | struct nfs4_setclientid_res *arg, |
| 5525 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | struct rpc_message msg = { |
| 5528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5529 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5530 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | int status; |
| 5533 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5534 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5535 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5536 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5537 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5538 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5539 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | return status; |
| 5541 | } |
| 5542 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5543 | struct nfs4_delegreturndata { |
| 5544 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5545 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5546 | struct nfs_fh fh; |
| 5547 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5548 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5549 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5550 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5551 | struct inode *inode; |
| 5552 | bool roc; |
| 5553 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5554 | }; |
| 5555 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5556 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5557 | { |
| 5558 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5559 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5560 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5561 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5562 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5563 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5564 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5565 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5566 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5567 | case -NFS4ERR_ADMIN_REVOKED: |
| 5568 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5569 | case -NFS4ERR_EXPIRED: |
| 5570 | nfs4_free_revoked_stateid(data->res.server, |
| 5571 | data->args.stateid, |
| 5572 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5573 | case -NFS4ERR_BAD_STATEID: |
| 5574 | case -NFS4ERR_OLD_STATEID: |
| 5575 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5576 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5577 | if (data->roc) |
| 5578 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5579 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5580 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5581 | if (nfs4_async_handle_error(task, data->res.server, |
| 5582 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5583 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5584 | return; |
| 5585 | } |
| 5586 | } |
| 5587 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | static void nfs4_delegreturn_release(void *calldata) |
| 5591 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5592 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5593 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5594 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5595 | if (inode) { |
| 5596 | if (data->roc) |
| 5597 | pnfs_roc_release(inode); |
| 5598 | nfs_iput_and_deactive(inode); |
| 5599 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5600 | kfree(calldata); |
| 5601 | } |
| 5602 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5603 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5604 | { |
| 5605 | struct nfs4_delegreturndata *d_data; |
| 5606 | |
| 5607 | d_data = (struct nfs4_delegreturndata *)data; |
| 5608 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5609 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5610 | return; |
| 5611 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5612 | if (d_data->roc) |
| 5613 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5614 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5615 | nfs4_setup_sequence(d_data->res.server, |
| 5616 | &d_data->args.seq_args, |
| 5617 | &d_data->res.seq_res, |
| 5618 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5619 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5620 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5621 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5622 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5623 | .rpc_call_done = nfs4_delegreturn_done, |
| 5624 | .rpc_release = nfs4_delegreturn_release, |
| 5625 | }; |
| 5626 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5627 | 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] | 5628 | { |
| 5629 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5630 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5631 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5632 | struct rpc_message msg = { |
| 5633 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5634 | .rpc_cred = cred, |
| 5635 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5636 | struct rpc_task_setup task_setup_data = { |
| 5637 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5638 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5639 | .callback_ops = &nfs4_delegreturn_ops, |
| 5640 | .flags = RPC_TASK_ASYNC, |
| 5641 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5642 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5643 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5644 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5645 | if (data == NULL) |
| 5646 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5647 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5648 | |
| 5649 | nfs4_state_protect(server->nfs_client, |
| 5650 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5651 | &task_setup_data.rpc_client, &msg); |
| 5652 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5653 | data->args.fhandle = &data->fh; |
| 5654 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5655 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5656 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5657 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5658 | data->res.fattr = &data->fattr; |
| 5659 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5660 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5661 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5662 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5663 | data->inode = nfs_igrab_and_active(inode); |
| 5664 | if (data->inode) |
| 5665 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5666 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5667 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5668 | msg.rpc_argp = &data->args; |
| 5669 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5670 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5671 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5672 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5673 | if (!issync) |
| 5674 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5675 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5676 | if (status != 0) |
| 5677 | goto out; |
| 5678 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5679 | if (status == 0) |
| 5680 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5681 | else |
| 5682 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5683 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5684 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5685 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5688 | 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] | 5689 | { |
| 5690 | struct nfs_server *server = NFS_SERVER(inode); |
| 5691 | struct nfs4_exception exception = { }; |
| 5692 | int err; |
| 5693 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5694 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5695 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | switch (err) { |
| 5697 | case -NFS4ERR_STALE_STATEID: |
| 5698 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | case 0: |
| 5700 | return 0; |
| 5701 | } |
| 5702 | err = nfs4_handle_exception(server, err, &exception); |
| 5703 | } while (exception.retry); |
| 5704 | return err; |
| 5705 | } |
| 5706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5708 | { |
| 5709 | struct inode *inode = state->inode; |
| 5710 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5711 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5712 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5714 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5716 | struct nfs_lockt_res res = { |
| 5717 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | }; |
| 5719 | struct rpc_message msg = { |
| 5720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5721 | .rpc_argp = &arg, |
| 5722 | .rpc_resp = &res, |
| 5723 | .rpc_cred = state->owner->so_cred, |
| 5724 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | struct nfs4_lock_state *lsp; |
| 5726 | int status; |
| 5727 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5728 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5729 | status = nfs4_set_lock_state(state, request); |
| 5730 | if (status != 0) |
| 5731 | goto out; |
| 5732 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5733 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5734 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5735 | 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] | 5736 | switch (status) { |
| 5737 | case 0: |
| 5738 | request->fl_type = F_UNLCK; |
| 5739 | break; |
| 5740 | case -NFS4ERR_DENIED: |
| 5741 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5743 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5744 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5745 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | return status; |
| 5747 | } |
| 5748 | |
| 5749 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5750 | { |
| 5751 | struct nfs4_exception exception = { }; |
| 5752 | int err; |
| 5753 | |
| 5754 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5755 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5756 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5757 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | &exception); |
| 5759 | } while (exception.retry); |
| 5760 | return err; |
| 5761 | } |
| 5762 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5763 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5764 | struct nfs_locku_args arg; |
| 5765 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5766 | struct nfs4_lock_state *lsp; |
| 5767 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5768 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5769 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5770 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5771 | }; |
| 5772 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5773 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5774 | struct nfs_open_context *ctx, |
| 5775 | struct nfs4_lock_state *lsp, |
| 5776 | struct nfs_seqid *seqid) |
| 5777 | { |
| 5778 | struct nfs4_unlockdata *p; |
| 5779 | struct inode *inode = lsp->ls_state->inode; |
| 5780 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5781 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5782 | if (p == NULL) |
| 5783 | return NULL; |
| 5784 | p->arg.fh = NFS_FH(inode); |
| 5785 | p->arg.fl = &p->fl; |
| 5786 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5787 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5788 | p->lsp = lsp; |
| 5789 | atomic_inc(&lsp->ls_count); |
| 5790 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5791 | p->ctx = get_nfs_open_context(ctx); |
| 5792 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5793 | p->server = NFS_SERVER(inode); |
| 5794 | return p; |
| 5795 | } |
| 5796 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5797 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5798 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5799 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5800 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5801 | nfs4_put_lock_state(calldata->lsp); |
| 5802 | put_nfs_open_context(calldata->ctx); |
| 5803 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5806 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5807 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5808 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5809 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5810 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5811 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5812 | switch (task->tk_status) { |
| 5813 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5814 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5815 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5816 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5817 | &calldata->res.stateid)) |
| 5818 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5819 | case -NFS4ERR_ADMIN_REVOKED: |
| 5820 | case -NFS4ERR_EXPIRED: |
| 5821 | nfs4_free_revoked_stateid(calldata->server, |
| 5822 | &calldata->arg.stateid, |
| 5823 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5824 | case -NFS4ERR_BAD_STATEID: |
| 5825 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5826 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5827 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5828 | &calldata->lsp->ls_stateid)) |
| 5829 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5830 | break; |
| 5831 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5832 | if (nfs4_async_handle_error(task, calldata->server, |
| 5833 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5834 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5835 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5836 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5839 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5840 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5841 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5843 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5844 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5845 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5846 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5847 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5848 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5849 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5850 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5851 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5852 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5853 | &calldata->res.seq_res, |
| 5854 | task) != 0) |
| 5855 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5856 | return; |
| 5857 | out_no_action: |
| 5858 | task->tk_action = NULL; |
| 5859 | out_wait: |
| 5860 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5861 | } |
| 5862 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5863 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5864 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5865 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5866 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5867 | }; |
| 5868 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5869 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5870 | struct nfs_open_context *ctx, |
| 5871 | struct nfs4_lock_state *lsp, |
| 5872 | struct nfs_seqid *seqid) |
| 5873 | { |
| 5874 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5875 | struct rpc_message msg = { |
| 5876 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5877 | .rpc_cred = ctx->cred, |
| 5878 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5879 | struct rpc_task_setup task_setup_data = { |
| 5880 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5881 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5882 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5883 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5884 | .flags = RPC_TASK_ASYNC, |
| 5885 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5886 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5887 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5888 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5889 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5890 | /* Ensure this is an unlock - when canceling a lock, the |
| 5891 | * canceled lock is passed in, and it won't be an unlock. |
| 5892 | */ |
| 5893 | fl->fl_type = F_UNLCK; |
| 5894 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5895 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5896 | if (data == NULL) { |
| 5897 | nfs_free_seqid(seqid); |
| 5898 | return ERR_PTR(-ENOMEM); |
| 5899 | } |
| 5900 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5901 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5902 | msg.rpc_argp = &data->arg; |
| 5903 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5904 | task_setup_data.callback_data = data; |
| 5905 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5906 | } |
| 5907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5909 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5910 | struct inode *inode = state->inode; |
| 5911 | struct nfs4_state_owner *sp = state->owner; |
| 5912 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5913 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5914 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5915 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5916 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5917 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5918 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5919 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5920 | status = nfs4_set_lock_state(state, request); |
| 5921 | /* Unlock _before_ we do the RPC call */ |
| 5922 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5923 | /* Exclude nfs_delegation_claim_locks() */ |
| 5924 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5925 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5926 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5927 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5928 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5929 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5930 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5931 | } |
| 5932 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5933 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5934 | if (status != 0) |
| 5935 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5936 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5937 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5938 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5939 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5940 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5941 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5942 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5943 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5944 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5945 | 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] | 5946 | status = PTR_ERR(task); |
| 5947 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5948 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5949 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5950 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5951 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5952 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5953 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5954 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5957 | struct nfs4_lockdata { |
| 5958 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5959 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5960 | struct nfs4_lock_state *lsp; |
| 5961 | struct nfs_open_context *ctx; |
| 5962 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5963 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5964 | int rpc_status; |
| 5965 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5966 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5967 | }; |
| 5968 | |
| 5969 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5970 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5971 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5972 | { |
| 5973 | struct nfs4_lockdata *p; |
| 5974 | struct inode *inode = lsp->ls_state->inode; |
| 5975 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5976 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5977 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5978 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5979 | if (p == NULL) |
| 5980 | return NULL; |
| 5981 | |
| 5982 | p->arg.fh = NFS_FH(inode); |
| 5983 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5984 | 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] | 5985 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5986 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5987 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5988 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5989 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5990 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5991 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5992 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5993 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5994 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5995 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5996 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5997 | atomic_inc(&lsp->ls_count); |
| 5998 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5999 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6000 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6001 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6002 | out_free_seqid: |
| 6003 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6004 | out_free: |
| 6005 | kfree(p); |
| 6006 | return NULL; |
| 6007 | } |
| 6008 | |
| 6009 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6010 | { |
| 6011 | struct nfs4_lockdata *data = calldata; |
| 6012 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6014 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6015 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6016 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6017 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6018 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6019 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6020 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6021 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6022 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6023 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6024 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6025 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6026 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6027 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6028 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6029 | &data->lsp->ls_stateid); |
| 6030 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6031 | if (!nfs4_valid_open_stateid(state)) { |
| 6032 | data->rpc_status = -EBADF; |
| 6033 | task->tk_action = NULL; |
| 6034 | goto out_release_open_seqid; |
| 6035 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6036 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6037 | if (nfs4_setup_sequence(data->server, |
| 6038 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6039 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6040 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6041 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6042 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6043 | nfs_release_seqid(data->arg.open_seqid); |
| 6044 | out_release_lock_seqid: |
| 6045 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6046 | out_wait: |
| 6047 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6048 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6049 | } |
| 6050 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6051 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6052 | { |
| 6053 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6054 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6055 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6056 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6057 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6058 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6059 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6060 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6061 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6062 | switch (task->tk_status) { |
| 6063 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6064 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6065 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6066 | if (data->arg.new_lock) { |
| 6067 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6068 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6069 | rpc_restart_call_prepare(task); |
| 6070 | break; |
| 6071 | } |
| 6072 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6073 | if (data->arg.new_lock_owner != 0) { |
| 6074 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6075 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6076 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6077 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6078 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6079 | break; |
| 6080 | case -NFS4ERR_BAD_STATEID: |
| 6081 | case -NFS4ERR_OLD_STATEID: |
| 6082 | case -NFS4ERR_STALE_STATEID: |
| 6083 | case -NFS4ERR_EXPIRED: |
| 6084 | if (data->arg.new_lock_owner != 0) { |
| 6085 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6086 | &lsp->ls_state->open_stateid)) |
| 6087 | rpc_restart_call_prepare(task); |
| 6088 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6089 | &lsp->ls_stateid)) |
| 6090 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6091 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6092 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6093 | } |
| 6094 | |
| 6095 | static void nfs4_lock_release(void *calldata) |
| 6096 | { |
| 6097 | struct nfs4_lockdata *data = calldata; |
| 6098 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6099 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6100 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6101 | if (data->cancelled != 0) { |
| 6102 | struct rpc_task *task; |
| 6103 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6104 | data->arg.lock_seqid); |
| 6105 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6106 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6107 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6108 | } else |
| 6109 | nfs_free_seqid(data->arg.lock_seqid); |
| 6110 | nfs4_put_lock_state(data->lsp); |
| 6111 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6112 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6113 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6114 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6115 | } |
| 6116 | |
| 6117 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6118 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6119 | .rpc_call_done = nfs4_lock_done, |
| 6120 | .rpc_release = nfs4_lock_release, |
| 6121 | }; |
| 6122 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6123 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6124 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6125 | switch (error) { |
| 6126 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6127 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6128 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6129 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6130 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6131 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6132 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6133 | break; |
| 6134 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6135 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6136 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6137 | }; |
| 6138 | } |
| 6139 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6140 | 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] | 6141 | { |
| 6142 | struct nfs4_lockdata *data; |
| 6143 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6144 | struct rpc_message msg = { |
| 6145 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6146 | .rpc_cred = state->owner->so_cred, |
| 6147 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6148 | struct rpc_task_setup task_setup_data = { |
| 6149 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6150 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6151 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6152 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6153 | .flags = RPC_TASK_ASYNC, |
| 6154 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6155 | int ret; |
| 6156 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6157 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6158 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6159 | fl->fl_u.nfs4_fl.owner, |
| 6160 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6161 | if (data == NULL) |
| 6162 | return -ENOMEM; |
| 6163 | if (IS_SETLKW(cmd)) |
| 6164 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6165 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6166 | msg.rpc_argp = &data->arg; |
| 6167 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6168 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6169 | if (recovery_type > NFS_LOCK_NEW) { |
| 6170 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6171 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6172 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6173 | } else |
| 6174 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6175 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6176 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6177 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6178 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6179 | if (ret == 0) { |
| 6180 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6181 | if (ret) |
| 6182 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6183 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6184 | } else |
| 6185 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6186 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6187 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6188 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6189 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6193 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6194 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6195 | struct nfs4_exception exception = { |
| 6196 | .inode = state->inode, |
| 6197 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6198 | int err; |
| 6199 | |
| 6200 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6201 | /* Cache the lock if possible... */ |
| 6202 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6203 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6204 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6205 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6206 | break; |
| 6207 | nfs4_handle_exception(server, err, &exception); |
| 6208 | } while (exception.retry); |
| 6209 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6213 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6214 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6215 | struct nfs4_exception exception = { |
| 6216 | .inode = state->inode, |
| 6217 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6218 | int err; |
| 6219 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6220 | err = nfs4_set_lock_state(state, request); |
| 6221 | if (err != 0) |
| 6222 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6223 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6224 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6225 | return 0; |
| 6226 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6227 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6228 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6229 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6230 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6231 | switch (err) { |
| 6232 | default: |
| 6233 | goto out; |
| 6234 | case -NFS4ERR_GRACE: |
| 6235 | case -NFS4ERR_DELAY: |
| 6236 | nfs4_handle_exception(server, err, &exception); |
| 6237 | err = 0; |
| 6238 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6239 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6240 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6241 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6244 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6245 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6246 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6247 | struct nfs4_lock_state *lsp; |
| 6248 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6249 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6250 | status = nfs4_set_lock_state(state, request); |
| 6251 | if (status != 0) |
| 6252 | return status; |
| 6253 | lsp = request->fl_u.nfs4_fl.owner; |
| 6254 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6255 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6256 | return 0; |
| 6257 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6258 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6259 | } |
| 6260 | #endif |
| 6261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6263 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6264 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6265 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6266 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6267 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6269 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6270 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6271 | if (status < 0) |
| 6272 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6273 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6274 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6275 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6276 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6277 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6278 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6279 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6280 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6281 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6282 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6283 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6284 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6285 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6286 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6287 | out: |
| 6288 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | return status; |
| 6290 | } |
| 6291 | |
| 6292 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6293 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6294 | struct nfs4_exception exception = { |
| 6295 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6296 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6297 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | int err; |
| 6299 | |
| 6300 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6301 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6302 | if (err == -NFS4ERR_DENIED) |
| 6303 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6305 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | } while (exception.retry); |
| 6307 | return err; |
| 6308 | } |
| 6309 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6310 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6311 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6312 | |
| 6313 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6314 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6315 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6316 | { |
| 6317 | int status = -ERESTARTSYS; |
| 6318 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6319 | |
| 6320 | while(!signalled()) { |
| 6321 | status = nfs4_proc_setlk(state, cmd, request); |
| 6322 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6323 | break; |
| 6324 | freezable_schedule_timeout_interruptible(timeout); |
| 6325 | timeout *= 2; |
| 6326 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6327 | status = -ERESTARTSYS; |
| 6328 | } |
| 6329 | return status; |
| 6330 | } |
| 6331 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6332 | #ifdef CONFIG_NFS_V4_1 |
| 6333 | struct nfs4_lock_waiter { |
| 6334 | struct task_struct *task; |
| 6335 | struct inode *inode; |
| 6336 | struct nfs_lowner *owner; |
| 6337 | bool notified; |
| 6338 | }; |
| 6339 | |
| 6340 | static int |
| 6341 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6342 | { |
| 6343 | int ret; |
| 6344 | struct cb_notify_lock_args *cbnl = key; |
| 6345 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6346 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6347 | *wowner = waiter->owner; |
| 6348 | |
| 6349 | /* Only wake if the callback was for the same owner */ |
| 6350 | if (lowner->clientid != wowner->clientid || |
| 6351 | lowner->id != wowner->id || |
| 6352 | lowner->s_dev != wowner->s_dev) |
| 6353 | return 0; |
| 6354 | |
| 6355 | /* Make sure it's for the right inode */ |
| 6356 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6357 | return 0; |
| 6358 | |
| 6359 | waiter->notified = true; |
| 6360 | |
| 6361 | /* override "private" so we can use default_wake_function */ |
| 6362 | wait->private = waiter->task; |
| 6363 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6364 | wait->private = waiter; |
| 6365 | return ret; |
| 6366 | } |
| 6367 | |
| 6368 | static int |
| 6369 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6370 | { |
| 6371 | int status = -ERESTARTSYS; |
| 6372 | unsigned long flags; |
| 6373 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6374 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6375 | struct nfs_client *clp = server->nfs_client; |
| 6376 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6377 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6378 | .id = lsp->ls_seqid.owner_id, |
| 6379 | .s_dev = server->s_dev }; |
| 6380 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6381 | .inode = state->inode, |
| 6382 | .owner = &owner, |
| 6383 | .notified = false }; |
| 6384 | wait_queue_t wait; |
| 6385 | |
| 6386 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6387 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6388 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6389 | |
| 6390 | init_wait(&wait); |
| 6391 | wait.private = &waiter; |
| 6392 | wait.func = nfs4_wake_lock_waiter; |
| 6393 | add_wait_queue(q, &wait); |
| 6394 | |
| 6395 | while(!signalled()) { |
| 6396 | status = nfs4_proc_setlk(state, cmd, request); |
| 6397 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6398 | break; |
| 6399 | |
| 6400 | status = -ERESTARTSYS; |
| 6401 | spin_lock_irqsave(&q->lock, flags); |
| 6402 | if (waiter.notified) { |
| 6403 | spin_unlock_irqrestore(&q->lock, flags); |
| 6404 | continue; |
| 6405 | } |
| 6406 | set_current_state(TASK_INTERRUPTIBLE); |
| 6407 | spin_unlock_irqrestore(&q->lock, flags); |
| 6408 | |
| 6409 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6410 | } |
| 6411 | |
| 6412 | finish_wait(q, &wait); |
| 6413 | return status; |
| 6414 | } |
| 6415 | #else /* !CONFIG_NFS_V4_1 */ |
| 6416 | static inline int |
| 6417 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6418 | { |
| 6419 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6420 | } |
| 6421 | #endif |
| 6422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | static int |
| 6424 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6425 | { |
| 6426 | struct nfs_open_context *ctx; |
| 6427 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6428 | int status; |
| 6429 | |
| 6430 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6431 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | state = ctx->state; |
| 6433 | |
| 6434 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6435 | return -EINVAL; |
| 6436 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6437 | if (IS_GETLK(cmd)) { |
| 6438 | if (state != NULL) |
| 6439 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6440 | return 0; |
| 6441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | |
| 6443 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6444 | return -EINVAL; |
| 6445 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6446 | if (request->fl_type == F_UNLCK) { |
| 6447 | if (state != NULL) |
| 6448 | return nfs4_proc_unlck(state, cmd, request); |
| 6449 | return 0; |
| 6450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6451 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6452 | if (state == NULL) |
| 6453 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6454 | |
| 6455 | if ((request->fl_flags & FL_POSIX) && |
| 6456 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6457 | return -ENOLCK; |
| 6458 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6459 | /* |
| 6460 | * Don't rely on the VFS having checked the file open mode, |
| 6461 | * since it won't do this for flock() locks. |
| 6462 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6463 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6464 | case F_RDLCK: |
| 6465 | if (!(filp->f_mode & FMODE_READ)) |
| 6466 | return -EBADF; |
| 6467 | break; |
| 6468 | case F_WRLCK: |
| 6469 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6470 | return -EBADF; |
| 6471 | } |
| 6472 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6473 | status = nfs4_set_lock_state(state, request); |
| 6474 | if (status != 0) |
| 6475 | return status; |
| 6476 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6477 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6478 | } |
| 6479 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6480 | 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] | 6481 | { |
| 6482 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6483 | int err; |
| 6484 | |
| 6485 | err = nfs4_set_lock_state(state, fl); |
| 6486 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6487 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6488 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6489 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6490 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6491 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6492 | struct nfs_release_lockowner_data { |
| 6493 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6494 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6495 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6496 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6497 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6498 | }; |
| 6499 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6500 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6501 | { |
| 6502 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6503 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6504 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6505 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6506 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6507 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6511 | { |
| 6512 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6513 | struct nfs_server *server = data->server; |
| 6514 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6515 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6516 | |
| 6517 | switch (task->tk_status) { |
| 6518 | case 0: |
| 6519 | renew_lease(server, data->timestamp); |
| 6520 | break; |
| 6521 | case -NFS4ERR_STALE_CLIENTID: |
| 6522 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6523 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6524 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6525 | case -NFS4ERR_LEASE_MOVED: |
| 6526 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6527 | if (nfs4_async_handle_error(task, server, |
| 6528 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6529 | rpc_restart_call_prepare(task); |
| 6530 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6531 | } |
| 6532 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6533 | static void nfs4_release_lockowner_release(void *calldata) |
| 6534 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6535 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6536 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6537 | kfree(calldata); |
| 6538 | } |
| 6539 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6540 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6541 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6542 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6543 | .rpc_release = nfs4_release_lockowner_release, |
| 6544 | }; |
| 6545 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6546 | static void |
| 6547 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6548 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6549 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6550 | struct rpc_message msg = { |
| 6551 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6552 | }; |
| 6553 | |
| 6554 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6555 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6556 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6557 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6558 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6559 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6560 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6561 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6562 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6563 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6564 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6565 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6566 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6567 | msg.rpc_resp = &data->res; |
| 6568 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6569 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6570 | } |
| 6571 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6572 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6573 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6574 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6575 | struct dentry *unused, struct inode *inode, |
| 6576 | const char *key, const void *buf, |
| 6577 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6578 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6579 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6580 | } |
| 6581 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6582 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6583 | struct dentry *unused, struct inode *inode, |
| 6584 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6585 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6586 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6587 | } |
| 6588 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6589 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6590 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6591 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6592 | } |
| 6593 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6594 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6595 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6596 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6597 | struct dentry *unused, struct inode *inode, |
| 6598 | const char *key, const void *buf, |
| 6599 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6600 | { |
| 6601 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6602 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6603 | |
| 6604 | return -EOPNOTSUPP; |
| 6605 | } |
| 6606 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6607 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6608 | struct dentry *unused, struct inode *inode, |
| 6609 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6610 | { |
| 6611 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6612 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6613 | return -EOPNOTSUPP; |
| 6614 | } |
| 6615 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6616 | static ssize_t |
| 6617 | 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] | 6618 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6619 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6620 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6621 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6622 | len = security_inode_listsecurity(inode, list, list_len); |
| 6623 | if (list_len && len > list_len) |
| 6624 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6625 | } |
| 6626 | return len; |
| 6627 | } |
| 6628 | |
| 6629 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6630 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6631 | .get = nfs4_xattr_get_nfs4_label, |
| 6632 | .set = nfs4_xattr_set_nfs4_label, |
| 6633 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6634 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6635 | #else |
| 6636 | |
| 6637 | static ssize_t |
| 6638 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6639 | { |
| 6640 | return 0; |
| 6641 | } |
| 6642 | |
| 6643 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6644 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6645 | /* |
| 6646 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6647 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6648 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6649 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6650 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6651 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6652 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6653 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6654 | return; |
| 6655 | |
| 6656 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6657 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6658 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6659 | fattr->nlink = 2; |
| 6660 | } |
| 6661 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6662 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6663 | const struct qstr *name, |
| 6664 | struct nfs4_fs_locations *fs_locations, |
| 6665 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6666 | { |
| 6667 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6668 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6669 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6670 | }; |
| 6671 | struct nfs4_fs_locations_arg args = { |
| 6672 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6673 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6674 | .page = page, |
| 6675 | .bitmask = bitmask, |
| 6676 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6677 | struct nfs4_fs_locations_res res = { |
| 6678 | .fs_locations = fs_locations, |
| 6679 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6680 | struct rpc_message msg = { |
| 6681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6682 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6683 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6684 | }; |
| 6685 | int status; |
| 6686 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6687 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6688 | |
| 6689 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6690 | * is not supported */ |
| 6691 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6692 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6693 | else |
| 6694 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6695 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6696 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6697 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6698 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6699 | 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] | 6700 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6701 | return status; |
| 6702 | } |
| 6703 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6704 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6705 | const struct qstr *name, |
| 6706 | struct nfs4_fs_locations *fs_locations, |
| 6707 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6708 | { |
| 6709 | struct nfs4_exception exception = { }; |
| 6710 | int err; |
| 6711 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6712 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6713 | fs_locations, page); |
| 6714 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6715 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6716 | &exception); |
| 6717 | } while (exception.retry); |
| 6718 | return err; |
| 6719 | } |
| 6720 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6721 | /* |
| 6722 | * This operation also signals the server that this client is |
| 6723 | * performing migration recovery. The server can stop returning |
| 6724 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6725 | * appended to this compound to identify the client ID which is |
| 6726 | * performing recovery. |
| 6727 | */ |
| 6728 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6729 | struct nfs4_fs_locations *locations, |
| 6730 | struct page *page, struct rpc_cred *cred) |
| 6731 | { |
| 6732 | struct nfs_server *server = NFS_SERVER(inode); |
| 6733 | struct rpc_clnt *clnt = server->client; |
| 6734 | u32 bitmask[2] = { |
| 6735 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6736 | }; |
| 6737 | struct nfs4_fs_locations_arg args = { |
| 6738 | .clientid = server->nfs_client->cl_clientid, |
| 6739 | .fh = NFS_FH(inode), |
| 6740 | .page = page, |
| 6741 | .bitmask = bitmask, |
| 6742 | .migration = 1, /* skip LOOKUP */ |
| 6743 | .renew = 1, /* append RENEW */ |
| 6744 | }; |
| 6745 | struct nfs4_fs_locations_res res = { |
| 6746 | .fs_locations = locations, |
| 6747 | .migration = 1, |
| 6748 | .renew = 1, |
| 6749 | }; |
| 6750 | struct rpc_message msg = { |
| 6751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6752 | .rpc_argp = &args, |
| 6753 | .rpc_resp = &res, |
| 6754 | .rpc_cred = cred, |
| 6755 | }; |
| 6756 | unsigned long now = jiffies; |
| 6757 | int status; |
| 6758 | |
| 6759 | nfs_fattr_init(&locations->fattr); |
| 6760 | locations->server = server; |
| 6761 | locations->nlocations = 0; |
| 6762 | |
| 6763 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6764 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6765 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6766 | &args.seq_args, &res.seq_res); |
| 6767 | if (status) |
| 6768 | return status; |
| 6769 | |
| 6770 | renew_lease(server, now); |
| 6771 | return 0; |
| 6772 | } |
| 6773 | |
| 6774 | #ifdef CONFIG_NFS_V4_1 |
| 6775 | |
| 6776 | /* |
| 6777 | * This operation also signals the server that this client is |
| 6778 | * performing migration recovery. The server can stop asserting |
| 6779 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6780 | * performing this operation is identified in the SEQUENCE |
| 6781 | * operation in this compound. |
| 6782 | * |
| 6783 | * When the client supports GETATTR(fs_locations_info), it can |
| 6784 | * be plumbed in here. |
| 6785 | */ |
| 6786 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6787 | struct nfs4_fs_locations *locations, |
| 6788 | struct page *page, struct rpc_cred *cred) |
| 6789 | { |
| 6790 | struct nfs_server *server = NFS_SERVER(inode); |
| 6791 | struct rpc_clnt *clnt = server->client; |
| 6792 | u32 bitmask[2] = { |
| 6793 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6794 | }; |
| 6795 | struct nfs4_fs_locations_arg args = { |
| 6796 | .fh = NFS_FH(inode), |
| 6797 | .page = page, |
| 6798 | .bitmask = bitmask, |
| 6799 | .migration = 1, /* skip LOOKUP */ |
| 6800 | }; |
| 6801 | struct nfs4_fs_locations_res res = { |
| 6802 | .fs_locations = locations, |
| 6803 | .migration = 1, |
| 6804 | }; |
| 6805 | struct rpc_message msg = { |
| 6806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6807 | .rpc_argp = &args, |
| 6808 | .rpc_resp = &res, |
| 6809 | .rpc_cred = cred, |
| 6810 | }; |
| 6811 | int status; |
| 6812 | |
| 6813 | nfs_fattr_init(&locations->fattr); |
| 6814 | locations->server = server; |
| 6815 | locations->nlocations = 0; |
| 6816 | |
| 6817 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6818 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6819 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6820 | &args.seq_args, &res.seq_res); |
| 6821 | if (status == NFS4_OK && |
| 6822 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6823 | status = -NFS4ERR_LEASE_MOVED; |
| 6824 | return status; |
| 6825 | } |
| 6826 | |
| 6827 | #endif /* CONFIG_NFS_V4_1 */ |
| 6828 | |
| 6829 | /** |
| 6830 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6831 | * @inode: inode on FSID that is migrating |
| 6832 | * @locations: result of query |
| 6833 | * @page: buffer |
| 6834 | * @cred: credential to use for this operation |
| 6835 | * |
| 6836 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6837 | * operation failed, or a negative errno if a local error occurred. |
| 6838 | * |
| 6839 | * On success, "locations" is filled in, but if the server has |
| 6840 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6841 | * asserted. |
| 6842 | * |
| 6843 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6844 | * from this client that require migration recovery. |
| 6845 | */ |
| 6846 | int nfs4_proc_get_locations(struct inode *inode, |
| 6847 | struct nfs4_fs_locations *locations, |
| 6848 | struct page *page, struct rpc_cred *cred) |
| 6849 | { |
| 6850 | struct nfs_server *server = NFS_SERVER(inode); |
| 6851 | struct nfs_client *clp = server->nfs_client; |
| 6852 | const struct nfs4_mig_recovery_ops *ops = |
| 6853 | clp->cl_mvops->mig_recovery_ops; |
| 6854 | struct nfs4_exception exception = { }; |
| 6855 | int status; |
| 6856 | |
| 6857 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6858 | (unsigned long long)server->fsid.major, |
| 6859 | (unsigned long long)server->fsid.minor, |
| 6860 | clp->cl_hostname); |
| 6861 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6862 | |
| 6863 | do { |
| 6864 | status = ops->get_locations(inode, locations, page, cred); |
| 6865 | if (status != -NFS4ERR_DELAY) |
| 6866 | break; |
| 6867 | nfs4_handle_exception(server, status, &exception); |
| 6868 | } while (exception.retry); |
| 6869 | return status; |
| 6870 | } |
| 6871 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6872 | /* |
| 6873 | * This operation also signals the server that this client is |
| 6874 | * performing "lease moved" recovery. The server can stop |
| 6875 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6876 | * is appended to this compound to identify the client ID which is |
| 6877 | * performing recovery. |
| 6878 | */ |
| 6879 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6880 | { |
| 6881 | struct nfs_server *server = NFS_SERVER(inode); |
| 6882 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6883 | struct rpc_clnt *clnt = server->client; |
| 6884 | struct nfs4_fsid_present_arg args = { |
| 6885 | .fh = NFS_FH(inode), |
| 6886 | .clientid = clp->cl_clientid, |
| 6887 | .renew = 1, /* append RENEW */ |
| 6888 | }; |
| 6889 | struct nfs4_fsid_present_res res = { |
| 6890 | .renew = 1, |
| 6891 | }; |
| 6892 | struct rpc_message msg = { |
| 6893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6894 | .rpc_argp = &args, |
| 6895 | .rpc_resp = &res, |
| 6896 | .rpc_cred = cred, |
| 6897 | }; |
| 6898 | unsigned long now = jiffies; |
| 6899 | int status; |
| 6900 | |
| 6901 | res.fh = nfs_alloc_fhandle(); |
| 6902 | if (res.fh == NULL) |
| 6903 | return -ENOMEM; |
| 6904 | |
| 6905 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6906 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6907 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6908 | &args.seq_args, &res.seq_res); |
| 6909 | nfs_free_fhandle(res.fh); |
| 6910 | if (status) |
| 6911 | return status; |
| 6912 | |
| 6913 | do_renew_lease(clp, now); |
| 6914 | return 0; |
| 6915 | } |
| 6916 | |
| 6917 | #ifdef CONFIG_NFS_V4_1 |
| 6918 | |
| 6919 | /* |
| 6920 | * This operation also signals the server that this client is |
| 6921 | * performing "lease moved" recovery. The server can stop asserting |
| 6922 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6923 | * this operation is identified in the SEQUENCE operation in this |
| 6924 | * compound. |
| 6925 | */ |
| 6926 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6927 | { |
| 6928 | struct nfs_server *server = NFS_SERVER(inode); |
| 6929 | struct rpc_clnt *clnt = server->client; |
| 6930 | struct nfs4_fsid_present_arg args = { |
| 6931 | .fh = NFS_FH(inode), |
| 6932 | }; |
| 6933 | struct nfs4_fsid_present_res res = { |
| 6934 | }; |
| 6935 | struct rpc_message msg = { |
| 6936 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6937 | .rpc_argp = &args, |
| 6938 | .rpc_resp = &res, |
| 6939 | .rpc_cred = cred, |
| 6940 | }; |
| 6941 | int status; |
| 6942 | |
| 6943 | res.fh = nfs_alloc_fhandle(); |
| 6944 | if (res.fh == NULL) |
| 6945 | return -ENOMEM; |
| 6946 | |
| 6947 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6948 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6949 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6950 | &args.seq_args, &res.seq_res); |
| 6951 | nfs_free_fhandle(res.fh); |
| 6952 | if (status == NFS4_OK && |
| 6953 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6954 | status = -NFS4ERR_LEASE_MOVED; |
| 6955 | return status; |
| 6956 | } |
| 6957 | |
| 6958 | #endif /* CONFIG_NFS_V4_1 */ |
| 6959 | |
| 6960 | /** |
| 6961 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6962 | * @inode: inode on FSID to check |
| 6963 | * @cred: credential to use for this operation |
| 6964 | * |
| 6965 | * Server indicates whether the FSID is present, moved, or not |
| 6966 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6967 | * condition for this client ID. |
| 6968 | * |
| 6969 | * Returns NFS4_OK if the FSID is present on this server, |
| 6970 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6971 | * NFS4ERR code if some error occurred on the server, or a |
| 6972 | * negative errno if a local failure occurred. |
| 6973 | */ |
| 6974 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6975 | { |
| 6976 | struct nfs_server *server = NFS_SERVER(inode); |
| 6977 | struct nfs_client *clp = server->nfs_client; |
| 6978 | const struct nfs4_mig_recovery_ops *ops = |
| 6979 | clp->cl_mvops->mig_recovery_ops; |
| 6980 | struct nfs4_exception exception = { }; |
| 6981 | int status; |
| 6982 | |
| 6983 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6984 | (unsigned long long)server->fsid.major, |
| 6985 | (unsigned long long)server->fsid.minor, |
| 6986 | clp->cl_hostname); |
| 6987 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6988 | |
| 6989 | do { |
| 6990 | status = ops->fsid_present(inode, cred); |
| 6991 | if (status != -NFS4ERR_DELAY) |
| 6992 | break; |
| 6993 | nfs4_handle_exception(server, status, &exception); |
| 6994 | } while (exception.retry); |
| 6995 | return status; |
| 6996 | } |
| 6997 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6998 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6999 | * If 'use_integrity' is true and the state managment nfs_client |
| 7000 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7001 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7002 | * Considerations sections. Otherwise, just use the user cred with the |
| 7003 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7004 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7005 | 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] | 7006 | { |
| 7007 | int status; |
| 7008 | struct nfs4_secinfo_arg args = { |
| 7009 | .dir_fh = NFS_FH(dir), |
| 7010 | .name = name, |
| 7011 | }; |
| 7012 | struct nfs4_secinfo_res res = { |
| 7013 | .flavors = flavors, |
| 7014 | }; |
| 7015 | struct rpc_message msg = { |
| 7016 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7017 | .rpc_argp = &args, |
| 7018 | .rpc_resp = &res, |
| 7019 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7020 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7021 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7022 | |
| 7023 | if (use_integrity) { |
| 7024 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7025 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7026 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7027 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7028 | |
| 7029 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7030 | |
| 7031 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7032 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7033 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7034 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7035 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7036 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7037 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7038 | if (cred) |
| 7039 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7040 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7041 | return status; |
| 7042 | } |
| 7043 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7044 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7045 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7046 | { |
| 7047 | struct nfs4_exception exception = { }; |
| 7048 | int err; |
| 7049 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7050 | err = -NFS4ERR_WRONGSEC; |
| 7051 | |
| 7052 | /* try to use integrity protection with machine cred */ |
| 7053 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7054 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7055 | |
| 7056 | /* |
| 7057 | * if unable to use integrity protection, or SECINFO with |
| 7058 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7059 | * disallowed by spec, but exists in deployed servers) use |
| 7060 | * the current filesystem's rpc_client and the user cred. |
| 7061 | */ |
| 7062 | if (err == -NFS4ERR_WRONGSEC) |
| 7063 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7064 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7065 | trace_nfs4_secinfo(dir, name, err); |
| 7066 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7067 | &exception); |
| 7068 | } while (exception.retry); |
| 7069 | return err; |
| 7070 | } |
| 7071 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7072 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7073 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7074 | * Check the exchange flags returned by the server for invalid flags, having |
| 7075 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7076 | * DS flags set. |
| 7077 | */ |
| 7078 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7079 | { |
| 7080 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7081 | goto out_inval; |
| 7082 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7083 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7084 | goto out_inval; |
| 7085 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7086 | goto out_inval; |
| 7087 | return NFS_OK; |
| 7088 | out_inval: |
| 7089 | return -NFS4ERR_INVAL; |
| 7090 | } |
| 7091 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7092 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7093 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7094 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7095 | { |
| 7096 | if (a->server_scope_sz == b->server_scope_sz && |
| 7097 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7098 | return true; |
| 7099 | |
| 7100 | return false; |
| 7101 | } |
| 7102 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7103 | static void |
| 7104 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7105 | { |
| 7106 | } |
| 7107 | |
| 7108 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7109 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7110 | }; |
| 7111 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7112 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7113 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7114 | * |
| 7115 | * The 4.1 client currently uses the same TCP connection for the |
| 7116 | * fore and backchannel. |
| 7117 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7118 | static |
| 7119 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7120 | struct rpc_xprt *xprt, |
| 7121 | struct nfs_client *clp, |
| 7122 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7123 | { |
| 7124 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7125 | struct nfs41_bind_conn_to_session_args args = { |
| 7126 | .client = clp, |
| 7127 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7128 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7129 | struct nfs41_bind_conn_to_session_res res; |
| 7130 | struct rpc_message msg = { |
| 7131 | .rpc_proc = |
| 7132 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7133 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7134 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7135 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7136 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7137 | struct rpc_task_setup task_setup_data = { |
| 7138 | .rpc_client = clnt, |
| 7139 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7140 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7141 | .rpc_message = &msg, |
| 7142 | .flags = RPC_TASK_TIMEOUT, |
| 7143 | }; |
| 7144 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7145 | |
| 7146 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7147 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7148 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7149 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7150 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7151 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7152 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7153 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7154 | args.dir = NFS4_CDFC4_FORE; |
| 7155 | |
| 7156 | task = rpc_run_task(&task_setup_data); |
| 7157 | if (!IS_ERR(task)) { |
| 7158 | status = task->tk_status; |
| 7159 | rpc_put_task(task); |
| 7160 | } else |
| 7161 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7162 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7163 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7164 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7165 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7166 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7167 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7168 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7169 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7170 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7171 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7172 | __func__); |
| 7173 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7174 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7175 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7176 | 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] | 7177 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7178 | __func__); |
| 7179 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7180 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7181 | } |
| 7182 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7183 | out: |
| 7184 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7185 | return status; |
| 7186 | } |
| 7187 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7188 | struct rpc_bind_conn_calldata { |
| 7189 | struct nfs_client *clp; |
| 7190 | struct rpc_cred *cred; |
| 7191 | }; |
| 7192 | |
| 7193 | static int |
| 7194 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7195 | struct rpc_xprt *xprt, |
| 7196 | void *calldata) |
| 7197 | { |
| 7198 | struct rpc_bind_conn_calldata *p = calldata; |
| 7199 | |
| 7200 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7201 | } |
| 7202 | |
| 7203 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7204 | { |
| 7205 | struct rpc_bind_conn_calldata data = { |
| 7206 | .clp = clp, |
| 7207 | .cred = cred, |
| 7208 | }; |
| 7209 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7210 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7211 | } |
| 7212 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7213 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7214 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7215 | * 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] | 7216 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7217 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7218 | .how = SP4_MACH_CRED, |
| 7219 | .enforce.u.words = { |
| 7220 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7221 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7222 | 1 << (OP_CREATE_SESSION - 32) | |
| 7223 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7224 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7225 | }, |
| 7226 | .allow.u.words = { |
| 7227 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7228 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7229 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7230 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7231 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7232 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7233 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7234 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7235 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7236 | 1 << (OP_FREE_STATEID - 32) | |
| 7237 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7238 | } |
| 7239 | }; |
| 7240 | |
| 7241 | /* |
| 7242 | * Select the state protection mode for client `clp' given the server results |
| 7243 | * from exchange_id in `sp'. |
| 7244 | * |
| 7245 | * Returns 0 on success, negative errno otherwise. |
| 7246 | */ |
| 7247 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7248 | struct nfs41_state_protection *sp) |
| 7249 | { |
| 7250 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7251 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7252 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7253 | 1 << (OP_CREATE_SESSION - 32) | |
| 7254 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7255 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7256 | }; |
| 7257 | unsigned int i; |
| 7258 | |
| 7259 | if (sp->how == SP4_MACH_CRED) { |
| 7260 | /* Print state protect result */ |
| 7261 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7262 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7263 | if (test_bit(i, sp->enforce.u.longs)) |
| 7264 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7265 | if (test_bit(i, sp->allow.u.longs)) |
| 7266 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7267 | } |
| 7268 | |
| 7269 | /* make sure nothing is on enforce list that isn't supported */ |
| 7270 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7271 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7272 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7273 | return -EINVAL; |
| 7274 | } |
| 7275 | } |
| 7276 | |
| 7277 | /* |
| 7278 | * Minimal mode - state operations are allowed to use machine |
| 7279 | * credential. Note this already happens by default, so the |
| 7280 | * client doesn't have to do anything more than the negotiation. |
| 7281 | * |
| 7282 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7283 | * we're already using the machine cred for exchange_id |
| 7284 | * and will never use a different cred. |
| 7285 | */ |
| 7286 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7287 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7288 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7289 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7290 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7291 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7292 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7293 | } else { |
| 7294 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7295 | return -EINVAL; |
| 7296 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7297 | |
| 7298 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7299 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7300 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7301 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7302 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7303 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7304 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7305 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7306 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7307 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7308 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7309 | &clp->cl_sp4_flags); |
| 7310 | } |
| 7311 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7312 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7313 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7314 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7315 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7316 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7317 | |
| 7318 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7319 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7320 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7321 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7322 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7323 | |
| 7324 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7325 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7326 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7327 | } |
| 7328 | |
| 7329 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7330 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7331 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7332 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | return 0; |
| 7336 | } |
| 7337 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7338 | struct nfs41_exchange_id_data { |
| 7339 | struct nfs41_exchange_id_res res; |
| 7340 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7341 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7342 | int rpc_status; |
| 7343 | }; |
| 7344 | |
| 7345 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7346 | { |
| 7347 | struct nfs41_exchange_id_data *cdata = |
| 7348 | (struct nfs41_exchange_id_data *)data; |
| 7349 | struct nfs_client *clp = cdata->args.client; |
| 7350 | int status = task->tk_status; |
| 7351 | |
| 7352 | trace_nfs4_exchange_id(clp, status); |
| 7353 | |
| 7354 | if (status == 0) |
| 7355 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7356 | |
| 7357 | if (cdata->xprt && status == 0) { |
| 7358 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7359 | cdata->xprt); |
| 7360 | goto out; |
| 7361 | } |
| 7362 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7363 | if (status == 0) |
| 7364 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7365 | |
| 7366 | if (status == 0) { |
| 7367 | clp->cl_clientid = cdata->res.clientid; |
| 7368 | clp->cl_exchange_flags = cdata->res.flags; |
| 7369 | /* Client ID is not confirmed */ |
| 7370 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7371 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7372 | &clp->cl_session->session_state); |
| 7373 | clp->cl_seqid = cdata->res.seqid; |
| 7374 | } |
| 7375 | |
| 7376 | kfree(clp->cl_serverowner); |
| 7377 | clp->cl_serverowner = cdata->res.server_owner; |
| 7378 | cdata->res.server_owner = NULL; |
| 7379 | |
| 7380 | /* use the most recent implementation id */ |
| 7381 | kfree(clp->cl_implid); |
| 7382 | clp->cl_implid = cdata->res.impl_id; |
| 7383 | cdata->res.impl_id = NULL; |
| 7384 | |
| 7385 | if (clp->cl_serverscope != NULL && |
| 7386 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7387 | cdata->res.server_scope)) { |
| 7388 | dprintk("%s: server_scope mismatch detected\n", |
| 7389 | __func__); |
| 7390 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7391 | kfree(clp->cl_serverscope); |
| 7392 | clp->cl_serverscope = NULL; |
| 7393 | } |
| 7394 | |
| 7395 | if (clp->cl_serverscope == NULL) { |
| 7396 | clp->cl_serverscope = cdata->res.server_scope; |
| 7397 | cdata->res.server_scope = NULL; |
| 7398 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7399 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7400 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7401 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7402 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7403 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7404 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7405 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | static void nfs4_exchange_id_release(void *data) |
| 7409 | { |
| 7410 | struct nfs41_exchange_id_data *cdata = |
| 7411 | (struct nfs41_exchange_id_data *)data; |
| 7412 | |
| 7413 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7414 | if (cdata->xprt) { |
| 7415 | xprt_put(cdata->xprt); |
| 7416 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7417 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7418 | kfree(cdata->res.impl_id); |
| 7419 | kfree(cdata->res.server_scope); |
| 7420 | kfree(cdata->res.server_owner); |
| 7421 | kfree(cdata); |
| 7422 | } |
| 7423 | |
| 7424 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7425 | .rpc_call_done = nfs4_exchange_id_done, |
| 7426 | .rpc_release = nfs4_exchange_id_release, |
| 7427 | }; |
| 7428 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7429 | /* |
| 7430 | * _nfs4_proc_exchange_id() |
| 7431 | * |
| 7432 | * Wrapper for EXCHANGE_ID operation. |
| 7433 | */ |
| 7434 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7435 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7436 | { |
| 7437 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7438 | struct rpc_message msg = { |
| 7439 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7440 | .rpc_cred = cred, |
| 7441 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7442 | struct rpc_task_setup task_setup_data = { |
| 7443 | .rpc_client = clp->cl_rpcclient, |
| 7444 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7445 | .rpc_message = &msg, |
| 7446 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7447 | }; |
| 7448 | struct nfs41_exchange_id_data *calldata; |
| 7449 | struct rpc_task *task; |
| 7450 | int status = -EIO; |
| 7451 | |
| 7452 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7453 | goto out; |
| 7454 | |
| 7455 | status = -ENOMEM; |
| 7456 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7457 | if (!calldata) |
| 7458 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7459 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7460 | if (!xprt) |
| 7461 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7462 | |
| 7463 | status = nfs4_init_uniform_client_string(clp); |
| 7464 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7465 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7466 | |
| 7467 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7468 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7469 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7470 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7471 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7472 | GFP_NOFS); |
| 7473 | status = -ENOMEM; |
| 7474 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7475 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7476 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7477 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7478 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7479 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7480 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7481 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7482 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7483 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7484 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7485 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7486 | switch (sp4_how) { |
| 7487 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7488 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7489 | break; |
| 7490 | |
| 7491 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7492 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7493 | break; |
| 7494 | |
| 7495 | default: |
| 7496 | /* unsupported! */ |
| 7497 | WARN_ON_ONCE(1); |
| 7498 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7499 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7500 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7501 | if (xprt) { |
| 7502 | calldata->xprt = xprt; |
| 7503 | task_setup_data.rpc_xprt = xprt; |
| 7504 | task_setup_data.flags = |
| 7505 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7506 | calldata->args.verifier = &clp->cl_confirm; |
| 7507 | } else { |
| 7508 | calldata->args.verifier = &verifier; |
| 7509 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7510 | calldata->args.client = clp; |
| 7511 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7512 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7513 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7514 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7515 | #else |
| 7516 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7517 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7518 | #endif |
| 7519 | msg.rpc_argp = &calldata->args; |
| 7520 | msg.rpc_resp = &calldata->res; |
| 7521 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7522 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7523 | task = rpc_run_task(&task_setup_data); |
| 7524 | if (IS_ERR(task)) { |
| 7525 | status = PTR_ERR(task); |
| 7526 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7527 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7528 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7529 | if (!xprt) { |
| 7530 | status = rpc_wait_for_completion_task(task); |
| 7531 | if (!status) |
| 7532 | status = calldata->rpc_status; |
| 7533 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7534 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7535 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7536 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7537 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7538 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7539 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7540 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7541 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7542 | clp->cl_implid->date.seconds, |
| 7543 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7544 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7545 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7546 | |
| 7547 | out_impl_id: |
| 7548 | kfree(calldata->res.impl_id); |
| 7549 | out_server_scope: |
| 7550 | kfree(calldata->res.server_scope); |
| 7551 | out_server_owner: |
| 7552 | kfree(calldata->res.server_owner); |
| 7553 | out_calldata: |
| 7554 | kfree(calldata); |
| 7555 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7556 | } |
| 7557 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7558 | /* |
| 7559 | * nfs4_proc_exchange_id() |
| 7560 | * |
| 7561 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7562 | * |
| 7563 | * Since the clientid has expired, all compounds using sessions |
| 7564 | * associated with the stale clientid will be returning |
| 7565 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7566 | * be in some phase of session reset. |
| 7567 | * |
| 7568 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7569 | */ |
| 7570 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7571 | { |
| 7572 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7573 | int status; |
| 7574 | |
| 7575 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7576 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7577 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7578 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7579 | if (!status) |
| 7580 | return 0; |
| 7581 | } |
| 7582 | |
| 7583 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7584 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7585 | } |
| 7586 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7587 | /** |
| 7588 | * nfs4_test_session_trunk |
| 7589 | * |
| 7590 | * This is an add_xprt_test() test function called from |
| 7591 | * rpc_clnt_setup_test_and_add_xprt. |
| 7592 | * |
| 7593 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7594 | * and is dereferrenced in nfs4_exchange_id_release |
| 7595 | * |
| 7596 | * Upon success, add the new transport to the rpc_clnt |
| 7597 | * |
| 7598 | * @clnt: struct rpc_clnt to get new transport |
| 7599 | * @xprt: the rpc_xprt to test |
| 7600 | * @data: call data for _nfs4_proc_exchange_id. |
| 7601 | */ |
| 7602 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7603 | void *data) |
| 7604 | { |
| 7605 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7606 | u32 sp4_how; |
| 7607 | |
| 7608 | dprintk("--> %s try %s\n", __func__, |
| 7609 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7610 | |
| 7611 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7612 | |
| 7613 | /* Test connection for session trunking. Async exchange_id call */ |
| 7614 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7615 | } |
| 7616 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7617 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7618 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7619 | struct rpc_cred *cred) |
| 7620 | { |
| 7621 | struct rpc_message msg = { |
| 7622 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7623 | .rpc_argp = clp, |
| 7624 | .rpc_cred = cred, |
| 7625 | }; |
| 7626 | int status; |
| 7627 | |
| 7628 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7629 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7630 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7631 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7632 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7633 | return status; |
| 7634 | } |
| 7635 | |
| 7636 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7637 | struct rpc_cred *cred) |
| 7638 | { |
| 7639 | unsigned int loop; |
| 7640 | int ret; |
| 7641 | |
| 7642 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7643 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7644 | switch (ret) { |
| 7645 | case -NFS4ERR_DELAY: |
| 7646 | case -NFS4ERR_CLIENTID_BUSY: |
| 7647 | ssleep(1); |
| 7648 | break; |
| 7649 | default: |
| 7650 | return ret; |
| 7651 | } |
| 7652 | } |
| 7653 | return 0; |
| 7654 | } |
| 7655 | |
| 7656 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7657 | { |
| 7658 | struct rpc_cred *cred; |
| 7659 | int ret = 0; |
| 7660 | |
| 7661 | if (clp->cl_mvops->minor_version < 1) |
| 7662 | goto out; |
| 7663 | if (clp->cl_exchange_flags == 0) |
| 7664 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7665 | if (clp->cl_preserve_clid) |
| 7666 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7667 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7668 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7669 | if (cred) |
| 7670 | put_rpccred(cred); |
| 7671 | switch (ret) { |
| 7672 | case 0: |
| 7673 | case -NFS4ERR_STALE_CLIENTID: |
| 7674 | clp->cl_exchange_flags = 0; |
| 7675 | } |
| 7676 | out: |
| 7677 | return ret; |
| 7678 | } |
| 7679 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7680 | struct nfs4_get_lease_time_data { |
| 7681 | struct nfs4_get_lease_time_args *args; |
| 7682 | struct nfs4_get_lease_time_res *res; |
| 7683 | struct nfs_client *clp; |
| 7684 | }; |
| 7685 | |
| 7686 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7687 | void *calldata) |
| 7688 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7689 | struct nfs4_get_lease_time_data *data = |
| 7690 | (struct nfs4_get_lease_time_data *)calldata; |
| 7691 | |
| 7692 | dprintk("--> %s\n", __func__); |
| 7693 | /* just setup sequence, do not trigger session recovery |
| 7694 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7695 | nfs41_setup_sequence(data->clp->cl_session, |
| 7696 | &data->args->la_seq_args, |
| 7697 | &data->res->lr_seq_res, |
| 7698 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7699 | dprintk("<-- %s\n", __func__); |
| 7700 | } |
| 7701 | |
| 7702 | /* |
| 7703 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7704 | * from sequence operation or clientid errors. |
| 7705 | */ |
| 7706 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7707 | { |
| 7708 | struct nfs4_get_lease_time_data *data = |
| 7709 | (struct nfs4_get_lease_time_data *)calldata; |
| 7710 | |
| 7711 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7712 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7713 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7714 | switch (task->tk_status) { |
| 7715 | case -NFS4ERR_DELAY: |
| 7716 | case -NFS4ERR_GRACE: |
| 7717 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7718 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7719 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7720 | /* fall through */ |
| 7721 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7722 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7723 | return; |
| 7724 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7725 | dprintk("<-- %s\n", __func__); |
| 7726 | } |
| 7727 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7728 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7729 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7730 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7731 | }; |
| 7732 | |
| 7733 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7734 | { |
| 7735 | struct rpc_task *task; |
| 7736 | struct nfs4_get_lease_time_args args; |
| 7737 | struct nfs4_get_lease_time_res res = { |
| 7738 | .lr_fsinfo = fsinfo, |
| 7739 | }; |
| 7740 | struct nfs4_get_lease_time_data data = { |
| 7741 | .args = &args, |
| 7742 | .res = &res, |
| 7743 | .clp = clp, |
| 7744 | }; |
| 7745 | struct rpc_message msg = { |
| 7746 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7747 | .rpc_argp = &args, |
| 7748 | .rpc_resp = &res, |
| 7749 | }; |
| 7750 | struct rpc_task_setup task_setup = { |
| 7751 | .rpc_client = clp->cl_rpcclient, |
| 7752 | .rpc_message = &msg, |
| 7753 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7754 | .callback_data = &data, |
| 7755 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7756 | }; |
| 7757 | int status; |
| 7758 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7759 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7760 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7761 | dprintk("--> %s\n", __func__); |
| 7762 | task = rpc_run_task(&task_setup); |
| 7763 | |
| 7764 | if (IS_ERR(task)) |
| 7765 | status = PTR_ERR(task); |
| 7766 | else { |
| 7767 | status = task->tk_status; |
| 7768 | rpc_put_task(task); |
| 7769 | } |
| 7770 | dprintk("<-- %s return %d\n", __func__, status); |
| 7771 | |
| 7772 | return status; |
| 7773 | } |
| 7774 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7775 | /* |
| 7776 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7777 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7778 | * use them. |
| 7779 | * |
| 7780 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7781 | * always set csa_cachethis to FALSE because the current implementation |
| 7782 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7783 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7784 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7785 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7786 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7787 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7788 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7789 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7790 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7791 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7792 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7793 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7794 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7795 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7796 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7797 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7798 | |
| 7799 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7800 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7801 | __func__, |
| 7802 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7803 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7804 | |
| 7805 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7806 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7807 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7808 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7809 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7810 | args->bc_attrs.max_reqs = min_t(unsigned short, max_session_cb_slots, 1); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7811 | |
| 7812 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7813 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7814 | __func__, |
| 7815 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7816 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7817 | args->bc_attrs.max_reqs); |
| 7818 | } |
| 7819 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7820 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7821 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7822 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7823 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7824 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7825 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7826 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7827 | return -EINVAL; |
| 7828 | /* |
| 7829 | * Our requested max_ops is the minimum we need; we're not |
| 7830 | * prepared to break up compounds into smaller pieces than that. |
| 7831 | * So, no point even trying to continue if the server won't |
| 7832 | * cooperate: |
| 7833 | */ |
| 7834 | if (rcvd->max_ops < sent->max_ops) |
| 7835 | return -EINVAL; |
| 7836 | if (rcvd->max_reqs == 0) |
| 7837 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7838 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7839 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7840 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7841 | } |
| 7842 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7843 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7844 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7845 | { |
| 7846 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7847 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7848 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7849 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7850 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7851 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7852 | return -EINVAL; |
| 7853 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7854 | return -EINVAL; |
| 7855 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7856 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7857 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7858 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7859 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7860 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7861 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7862 | return 0; |
| 7863 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7864 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7865 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7866 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7867 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7868 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7869 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7870 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7871 | if (ret) |
| 7872 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7873 | return nfs4_verify_back_channel_attrs(args, res); |
| 7874 | } |
| 7875 | |
| 7876 | static void nfs4_update_session(struct nfs4_session *session, |
| 7877 | struct nfs41_create_session_res *res) |
| 7878 | { |
| 7879 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7880 | /* Mark client id and session as being confirmed */ |
| 7881 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7882 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7883 | session->flags = res->flags; |
| 7884 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7885 | if (res->flags & SESSION4_BACK_CHAN) |
| 7886 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7887 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7888 | } |
| 7889 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7890 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7891 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7892 | { |
| 7893 | struct nfs4_session *session = clp->cl_session; |
| 7894 | struct nfs41_create_session_args args = { |
| 7895 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7896 | .clientid = clp->cl_clientid, |
| 7897 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7898 | .cb_program = NFS4_CALLBACK, |
| 7899 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7900 | struct nfs41_create_session_res res; |
| 7901 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7902 | struct rpc_message msg = { |
| 7903 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7904 | .rpc_argp = &args, |
| 7905 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7906 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7907 | }; |
| 7908 | int status; |
| 7909 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7910 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7911 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7912 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7913 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7914 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7915 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7916 | switch (status) { |
| 7917 | case -NFS4ERR_STALE_CLIENTID: |
| 7918 | case -NFS4ERR_DELAY: |
| 7919 | case -ETIMEDOUT: |
| 7920 | case -EACCES: |
| 7921 | case -EAGAIN: |
| 7922 | goto out; |
| 7923 | }; |
| 7924 | |
| 7925 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7926 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7927 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7928 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7929 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7930 | if (status) |
| 7931 | goto out; |
| 7932 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7933 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7934 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7935 | return status; |
| 7936 | } |
| 7937 | |
| 7938 | /* |
| 7939 | * Issues a CREATE_SESSION operation to the server. |
| 7940 | * It is the responsibility of the caller to verify the session is |
| 7941 | * expired before calling this routine. |
| 7942 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7943 | 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] | 7944 | { |
| 7945 | int status; |
| 7946 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7947 | struct nfs4_session *session = clp->cl_session; |
| 7948 | |
| 7949 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7950 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7951 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7952 | if (status) |
| 7953 | goto out; |
| 7954 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7955 | /* Init or reset the session slot tables */ |
| 7956 | status = nfs4_setup_session_slot_tables(session); |
| 7957 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7958 | if (status) |
| 7959 | goto out; |
| 7960 | |
| 7961 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7962 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7963 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7964 | out: |
| 7965 | dprintk("<-- %s\n", __func__); |
| 7966 | return status; |
| 7967 | } |
| 7968 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7969 | /* |
| 7970 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7971 | * The caller must serialize access to this routine. |
| 7972 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7973 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7974 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7975 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7976 | struct rpc_message msg = { |
| 7977 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7978 | .rpc_argp = session, |
| 7979 | .rpc_cred = cred, |
| 7980 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7981 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7982 | |
| 7983 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7984 | |
| 7985 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7986 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7987 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7988 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7989 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7990 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7991 | |
| 7992 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7993 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7994 | "Session has been destroyed regardless...\n", status); |
| 7995 | |
| 7996 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7997 | return status; |
| 7998 | } |
| 7999 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8000 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8001 | * Renew the cl_session lease. |
| 8002 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8003 | struct nfs4_sequence_data { |
| 8004 | struct nfs_client *clp; |
| 8005 | struct nfs4_sequence_args args; |
| 8006 | struct nfs4_sequence_res res; |
| 8007 | }; |
| 8008 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8009 | static void nfs41_sequence_release(void *data) |
| 8010 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8011 | struct nfs4_sequence_data *calldata = data; |
| 8012 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8013 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8014 | if (atomic_read(&clp->cl_count) > 1) |
| 8015 | nfs4_schedule_state_renewal(clp); |
| 8016 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8017 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8018 | } |
| 8019 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8020 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8021 | { |
| 8022 | switch(task->tk_status) { |
| 8023 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8024 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8025 | return -EAGAIN; |
| 8026 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8027 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8028 | } |
| 8029 | return 0; |
| 8030 | } |
| 8031 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8032 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8033 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8034 | struct nfs4_sequence_data *calldata = data; |
| 8035 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8036 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8037 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8038 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8039 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8040 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8041 | if (task->tk_status < 0) { |
| 8042 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8043 | if (atomic_read(&clp->cl_count) == 1) |
| 8044 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8045 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8046 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8047 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8048 | return; |
| 8049 | } |
| 8050 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8051 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8052 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8053 | dprintk("<-- %s\n", __func__); |
| 8054 | } |
| 8055 | |
| 8056 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8057 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8058 | struct nfs4_sequence_data *calldata = data; |
| 8059 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8060 | struct nfs4_sequence_args *args; |
| 8061 | struct nfs4_sequence_res *res; |
| 8062 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8063 | args = task->tk_msg.rpc_argp; |
| 8064 | res = task->tk_msg.rpc_resp; |
| 8065 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8066 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8067 | } |
| 8068 | |
| 8069 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8070 | .rpc_call_done = nfs41_sequence_call_done, |
| 8071 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8072 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8073 | }; |
| 8074 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8075 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8076 | struct rpc_cred *cred, |
| 8077 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8078 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8079 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8080 | struct rpc_message msg = { |
| 8081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8082 | .rpc_cred = cred, |
| 8083 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8084 | struct rpc_task_setup task_setup_data = { |
| 8085 | .rpc_client = clp->cl_rpcclient, |
| 8086 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8087 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8088 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8089 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8090 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8091 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8092 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8093 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8094 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8095 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8096 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8097 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8098 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8099 | if (is_privileged) |
| 8100 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8101 | msg.rpc_argp = &calldata->args; |
| 8102 | msg.rpc_resp = &calldata->res; |
| 8103 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8104 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8105 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8106 | return rpc_run_task(&task_setup_data); |
| 8107 | } |
| 8108 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8109 | 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] | 8110 | { |
| 8111 | struct rpc_task *task; |
| 8112 | int ret = 0; |
| 8113 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8114 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8115 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8116 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8117 | if (IS_ERR(task)) |
| 8118 | ret = PTR_ERR(task); |
| 8119 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8120 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8121 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8122 | return ret; |
| 8123 | } |
| 8124 | |
| 8125 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8126 | { |
| 8127 | struct rpc_task *task; |
| 8128 | int ret; |
| 8129 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8130 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8131 | if (IS_ERR(task)) { |
| 8132 | ret = PTR_ERR(task); |
| 8133 | goto out; |
| 8134 | } |
| 8135 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8136 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8137 | ret = task->tk_status; |
| 8138 | rpc_put_task(task); |
| 8139 | out: |
| 8140 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8141 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8142 | } |
| 8143 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8144 | struct nfs4_reclaim_complete_data { |
| 8145 | struct nfs_client *clp; |
| 8146 | struct nfs41_reclaim_complete_args arg; |
| 8147 | struct nfs41_reclaim_complete_res res; |
| 8148 | }; |
| 8149 | |
| 8150 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8151 | { |
| 8152 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8153 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8154 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8155 | &calldata->arg.seq_args, |
| 8156 | &calldata->res.seq_res, |
| 8157 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8158 | } |
| 8159 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8160 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8161 | { |
| 8162 | switch(task->tk_status) { |
| 8163 | case 0: |
| 8164 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8165 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8166 | break; |
| 8167 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8168 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8169 | /* fall through */ |
| 8170 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8171 | return -EAGAIN; |
| 8172 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8173 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8174 | } |
| 8175 | return 0; |
| 8176 | } |
| 8177 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8178 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8179 | { |
| 8180 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8181 | struct nfs_client *clp = calldata->clp; |
| 8182 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8183 | |
| 8184 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8185 | if (!nfs41_sequence_done(task, res)) |
| 8186 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8187 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8188 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8189 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8190 | rpc_restart_call_prepare(task); |
| 8191 | return; |
| 8192 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8193 | dprintk("<-- %s\n", __func__); |
| 8194 | } |
| 8195 | |
| 8196 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8197 | { |
| 8198 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8199 | |
| 8200 | kfree(calldata); |
| 8201 | } |
| 8202 | |
| 8203 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8204 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8205 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8206 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8207 | }; |
| 8208 | |
| 8209 | /* |
| 8210 | * Issue a global reclaim complete. |
| 8211 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8212 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8213 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8214 | { |
| 8215 | struct nfs4_reclaim_complete_data *calldata; |
| 8216 | struct rpc_task *task; |
| 8217 | struct rpc_message msg = { |
| 8218 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8219 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8220 | }; |
| 8221 | struct rpc_task_setup task_setup_data = { |
| 8222 | .rpc_client = clp->cl_rpcclient, |
| 8223 | .rpc_message = &msg, |
| 8224 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8225 | .flags = RPC_TASK_ASYNC, |
| 8226 | }; |
| 8227 | int status = -ENOMEM; |
| 8228 | |
| 8229 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8230 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8231 | if (calldata == NULL) |
| 8232 | goto out; |
| 8233 | calldata->clp = clp; |
| 8234 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8235 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8236 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8237 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8238 | msg.rpc_argp = &calldata->arg; |
| 8239 | msg.rpc_resp = &calldata->res; |
| 8240 | task_setup_data.callback_data = calldata; |
| 8241 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8242 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8243 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8244 | goto out; |
| 8245 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8246 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8247 | if (status == 0) |
| 8248 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8249 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8250 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8251 | out: |
| 8252 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8253 | return status; |
| 8254 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8255 | |
| 8256 | static void |
| 8257 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8258 | { |
| 8259 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8260 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8261 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8262 | |
| 8263 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8264 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8265 | &lgp->res.seq_res, task); |
| 8266 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8267 | } |
| 8268 | |
| 8269 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8270 | { |
| 8271 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8272 | |
| 8273 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8274 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8275 | dprintk("<-- %s\n", __func__); |
| 8276 | } |
| 8277 | |
| 8278 | static int |
| 8279 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8280 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8281 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8282 | struct inode *inode = lgp->args.inode; |
| 8283 | struct nfs_server *server = NFS_SERVER(inode); |
| 8284 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8285 | int nfs4err = task->tk_status; |
| 8286 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8287 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8288 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8289 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8290 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8291 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8292 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8293 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8294 | |
| 8295 | /* |
| 8296 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8297 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8298 | * retry go inband. |
| 8299 | */ |
| 8300 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8301 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8302 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8303 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8304 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8305 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8306 | */ |
| 8307 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8308 | status = -EOVERFLOW; |
| 8309 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8310 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8311 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8312 | * (or clients) writing to the same RAID stripe except when |
| 8313 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8314 | * |
| 8315 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8316 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8317 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8318 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8319 | if (lgp->args.minlength == 0) { |
| 8320 | status = -EOVERFLOW; |
| 8321 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8322 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8323 | status = -EBUSY; |
| 8324 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8325 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8326 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8327 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8328 | case -NFS4ERR_DELEG_REVOKED: |
| 8329 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8330 | case -NFS4ERR_EXPIRED: |
| 8331 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8332 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8333 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8334 | lo = NFS_I(inode)->layout; |
| 8335 | /* If the open stateid was bad, then recover it. */ |
| 8336 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8337 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8338 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8339 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8340 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8341 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8342 | break; |
| 8343 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8344 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8345 | /* |
| 8346 | * Mark the bad layout state as invalid, then retry |
| 8347 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8348 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8349 | spin_unlock(&inode->i_lock); |
| 8350 | pnfs_free_lseg_list(&head); |
| 8351 | status = -EAGAIN; |
| 8352 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8353 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8354 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8355 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8356 | if (!status) { |
| 8357 | if (exception->retry) |
| 8358 | status = -EAGAIN; |
| 8359 | else |
| 8360 | status = err; |
| 8361 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8362 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8363 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8364 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8365 | } |
| 8366 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8367 | static size_t max_response_pages(struct nfs_server *server) |
| 8368 | { |
| 8369 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8370 | return nfs_page_array_len(0, max_resp_sz); |
| 8371 | } |
| 8372 | |
| 8373 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8374 | { |
| 8375 | int i; |
| 8376 | |
| 8377 | if (!pages) |
| 8378 | return; |
| 8379 | |
| 8380 | for (i = 0; i < size; i++) { |
| 8381 | if (!pages[i]) |
| 8382 | break; |
| 8383 | __free_page(pages[i]); |
| 8384 | } |
| 8385 | kfree(pages); |
| 8386 | } |
| 8387 | |
| 8388 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8389 | { |
| 8390 | struct page **pages; |
| 8391 | int i; |
| 8392 | |
| 8393 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8394 | if (!pages) { |
| 8395 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8396 | return NULL; |
| 8397 | } |
| 8398 | |
| 8399 | for (i = 0; i < size; i++) { |
| 8400 | pages[i] = alloc_page(gfp_flags); |
| 8401 | if (!pages[i]) { |
| 8402 | dprintk("%s: failed to allocate page\n", __func__); |
| 8403 | nfs4_free_pages(pages, size); |
| 8404 | return NULL; |
| 8405 | } |
| 8406 | } |
| 8407 | |
| 8408 | return pages; |
| 8409 | } |
| 8410 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8411 | static void nfs4_layoutget_release(void *calldata) |
| 8412 | { |
| 8413 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8414 | struct inode *inode = lgp->args.inode; |
| 8415 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8416 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8417 | |
| 8418 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8419 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8420 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8421 | put_nfs_open_context(lgp->args.ctx); |
| 8422 | kfree(calldata); |
| 8423 | dprintk("<-- %s\n", __func__); |
| 8424 | } |
| 8425 | |
| 8426 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8427 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8428 | .rpc_call_done = nfs4_layoutget_done, |
| 8429 | .rpc_release = nfs4_layoutget_release, |
| 8430 | }; |
| 8431 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8432 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8433 | 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] | 8434 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8435 | struct inode *inode = lgp->args.inode; |
| 8436 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8437 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8438 | struct rpc_task *task; |
| 8439 | struct rpc_message msg = { |
| 8440 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8441 | .rpc_argp = &lgp->args, |
| 8442 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8443 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8444 | }; |
| 8445 | struct rpc_task_setup task_setup_data = { |
| 8446 | .rpc_client = server->client, |
| 8447 | .rpc_message = &msg, |
| 8448 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8449 | .callback_data = lgp, |
| 8450 | .flags = RPC_TASK_ASYNC, |
| 8451 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8452 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8453 | struct nfs4_exception exception = { |
| 8454 | .inode = inode, |
| 8455 | .timeout = *timeout, |
| 8456 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8457 | int status = 0; |
| 8458 | |
| 8459 | dprintk("--> %s\n", __func__); |
| 8460 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8461 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8462 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8463 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8464 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8465 | if (!lgp->args.layout.pages) { |
| 8466 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8467 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8468 | } |
| 8469 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8470 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8471 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8472 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8473 | 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] | 8474 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8475 | task = rpc_run_task(&task_setup_data); |
| 8476 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8477 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8478 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8479 | if (status == 0) { |
| 8480 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8481 | *timeout = exception.timeout; |
| 8482 | } |
| 8483 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8484 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8485 | &lgp->args.range, |
| 8486 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8487 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8488 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8489 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8490 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8491 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8492 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8493 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8494 | rpc_put_task(task); |
| 8495 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8496 | if (status) |
| 8497 | return ERR_PTR(status); |
| 8498 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8499 | } |
| 8500 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8501 | static void |
| 8502 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8503 | { |
| 8504 | struct nfs4_layoutreturn *lrp = calldata; |
| 8505 | |
| 8506 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8507 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8508 | &lrp->args.seq_args, |
| 8509 | &lrp->res.seq_res, |
| 8510 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8514 | { |
| 8515 | struct nfs4_layoutreturn *lrp = calldata; |
| 8516 | struct nfs_server *server; |
| 8517 | |
| 8518 | dprintk("--> %s\n", __func__); |
| 8519 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8520 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8521 | return; |
| 8522 | |
| 8523 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8524 | switch (task->tk_status) { |
| 8525 | default: |
| 8526 | task->tk_status = 0; |
| 8527 | case 0: |
| 8528 | break; |
| 8529 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8530 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8531 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8532 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8533 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8534 | return; |
| 8535 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8536 | dprintk("<-- %s\n", __func__); |
| 8537 | } |
| 8538 | |
| 8539 | static void nfs4_layoutreturn_release(void *calldata) |
| 8540 | { |
| 8541 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8542 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8543 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8544 | |
| 8545 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8546 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8547 | if (lrp->res.lrs_present) { |
| 8548 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8549 | &lrp->args.range, |
| 8550 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8551 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8552 | } else |
| 8553 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8554 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8555 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8556 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8557 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8558 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8559 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8560 | kfree(calldata); |
| 8561 | dprintk("<-- %s\n", __func__); |
| 8562 | } |
| 8563 | |
| 8564 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8565 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8566 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8567 | .rpc_release = nfs4_layoutreturn_release, |
| 8568 | }; |
| 8569 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8570 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8571 | { |
| 8572 | struct rpc_task *task; |
| 8573 | struct rpc_message msg = { |
| 8574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8575 | .rpc_argp = &lrp->args, |
| 8576 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8577 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8578 | }; |
| 8579 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8580 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8581 | .rpc_message = &msg, |
| 8582 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8583 | .callback_data = lrp, |
| 8584 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8585 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8586 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8587 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8588 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8589 | &task_setup_data.rpc_client, &msg); |
| 8590 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8591 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8592 | if (!sync) { |
| 8593 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8594 | if (!lrp->inode) { |
| 8595 | nfs4_layoutreturn_release(lrp); |
| 8596 | return -EAGAIN; |
| 8597 | } |
| 8598 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8599 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8600 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8601 | task = rpc_run_task(&task_setup_data); |
| 8602 | if (IS_ERR(task)) |
| 8603 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8604 | if (sync) |
| 8605 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8606 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8607 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8608 | rpc_put_task(task); |
| 8609 | return status; |
| 8610 | } |
| 8611 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8612 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8613 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8614 | struct pnfs_device *pdev, |
| 8615 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8616 | { |
| 8617 | struct nfs4_getdeviceinfo_args args = { |
| 8618 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8619 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8620 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8621 | }; |
| 8622 | struct nfs4_getdeviceinfo_res res = { |
| 8623 | .pdev = pdev, |
| 8624 | }; |
| 8625 | struct rpc_message msg = { |
| 8626 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8627 | .rpc_argp = &args, |
| 8628 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8629 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8630 | }; |
| 8631 | int status; |
| 8632 | |
| 8633 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8634 | 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] | 8635 | if (res.notification & ~args.notify_types) |
| 8636 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8637 | if (res.notification != args.notify_types) |
| 8638 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8639 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8640 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8641 | |
| 8642 | return status; |
| 8643 | } |
| 8644 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8645 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8646 | struct pnfs_device *pdev, |
| 8647 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8648 | { |
| 8649 | struct nfs4_exception exception = { }; |
| 8650 | int err; |
| 8651 | |
| 8652 | do { |
| 8653 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8654 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8655 | &exception); |
| 8656 | } while (exception.retry); |
| 8657 | return err; |
| 8658 | } |
| 8659 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8660 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8661 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8662 | { |
| 8663 | struct nfs4_layoutcommit_data *data = calldata; |
| 8664 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8665 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8666 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8667 | nfs41_setup_sequence(session, |
| 8668 | &data->args.seq_args, |
| 8669 | &data->res.seq_res, |
| 8670 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8671 | } |
| 8672 | |
| 8673 | static void |
| 8674 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8675 | { |
| 8676 | struct nfs4_layoutcommit_data *data = calldata; |
| 8677 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8678 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8679 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8680 | return; |
| 8681 | |
| 8682 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8683 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8684 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8685 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8686 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8687 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8688 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8689 | break; |
| 8690 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8691 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8692 | rpc_restart_call_prepare(task); |
| 8693 | return; |
| 8694 | } |
| 8695 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8696 | } |
| 8697 | |
| 8698 | static void nfs4_layoutcommit_release(void *calldata) |
| 8699 | { |
| 8700 | struct nfs4_layoutcommit_data *data = calldata; |
| 8701 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8702 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8703 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8704 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8705 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8706 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8707 | kfree(data); |
| 8708 | } |
| 8709 | |
| 8710 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8711 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8712 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8713 | .rpc_release = nfs4_layoutcommit_release, |
| 8714 | }; |
| 8715 | |
| 8716 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8717 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8718 | { |
| 8719 | struct rpc_message msg = { |
| 8720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8721 | .rpc_argp = &data->args, |
| 8722 | .rpc_resp = &data->res, |
| 8723 | .rpc_cred = data->cred, |
| 8724 | }; |
| 8725 | struct rpc_task_setup task_setup_data = { |
| 8726 | .task = &data->task, |
| 8727 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8728 | .rpc_message = &msg, |
| 8729 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8730 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8731 | }; |
| 8732 | struct rpc_task *task; |
| 8733 | int status = 0; |
| 8734 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8735 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8736 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8737 | data->args.lastbytewritten, |
| 8738 | data->args.inode->i_ino); |
| 8739 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8740 | if (!sync) { |
| 8741 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8742 | if (data->inode == NULL) { |
| 8743 | nfs4_layoutcommit_release(data); |
| 8744 | return -EAGAIN; |
| 8745 | } |
| 8746 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8747 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8748 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8749 | task = rpc_run_task(&task_setup_data); |
| 8750 | if (IS_ERR(task)) |
| 8751 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8752 | if (sync) |
| 8753 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8754 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8755 | dprintk("%s: status %d\n", __func__, status); |
| 8756 | rpc_put_task(task); |
| 8757 | return status; |
| 8758 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8759 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8760 | /** |
| 8761 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8762 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8763 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8764 | static int |
| 8765 | _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] | 8766 | struct nfs_fsinfo *info, |
| 8767 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8768 | { |
| 8769 | struct nfs41_secinfo_no_name_args args = { |
| 8770 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8771 | }; |
| 8772 | struct nfs4_secinfo_res res = { |
| 8773 | .flavors = flavors, |
| 8774 | }; |
| 8775 | struct rpc_message msg = { |
| 8776 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8777 | .rpc_argp = &args, |
| 8778 | .rpc_resp = &res, |
| 8779 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8780 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8781 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8782 | int status; |
| 8783 | |
| 8784 | if (use_integrity) { |
| 8785 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8786 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8787 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8788 | } |
| 8789 | |
| 8790 | dprintk("--> %s\n", __func__); |
| 8791 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8792 | &res.seq_res, 0); |
| 8793 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8794 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8795 | if (cred) |
| 8796 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8797 | |
| 8798 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8799 | } |
| 8800 | |
| 8801 | static int |
| 8802 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8803 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8804 | { |
| 8805 | struct nfs4_exception exception = { }; |
| 8806 | int err; |
| 8807 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8808 | /* first try using integrity protection */ |
| 8809 | err = -NFS4ERR_WRONGSEC; |
| 8810 | |
| 8811 | /* try to use integrity protection with machine cred */ |
| 8812 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8813 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8814 | flavors, true); |
| 8815 | |
| 8816 | /* |
| 8817 | * if unable to use integrity protection, or SECINFO with |
| 8818 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8819 | * disallowed by spec, but exists in deployed servers) use |
| 8820 | * the current filesystem's rpc_client and the user cred. |
| 8821 | */ |
| 8822 | if (err == -NFS4ERR_WRONGSEC) |
| 8823 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8824 | flavors, false); |
| 8825 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8826 | switch (err) { |
| 8827 | case 0: |
| 8828 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8829 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8830 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8831 | default: |
| 8832 | err = nfs4_handle_exception(server, err, &exception); |
| 8833 | } |
| 8834 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8835 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8836 | return err; |
| 8837 | } |
| 8838 | |
| 8839 | static int |
| 8840 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8841 | struct nfs_fsinfo *info) |
| 8842 | { |
| 8843 | int err; |
| 8844 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8845 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8846 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8847 | struct nfs4_secinfo4 *secinfo; |
| 8848 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8849 | |
| 8850 | page = alloc_page(GFP_KERNEL); |
| 8851 | if (!page) { |
| 8852 | err = -ENOMEM; |
| 8853 | goto out; |
| 8854 | } |
| 8855 | |
| 8856 | flavors = page_address(page); |
| 8857 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8858 | |
| 8859 | /* |
| 8860 | * Fall back on "guess and check" method if |
| 8861 | * the server doesn't support SECINFO_NO_NAME |
| 8862 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8863 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8864 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8865 | goto out_freepage; |
| 8866 | } |
| 8867 | if (err) |
| 8868 | goto out_freepage; |
| 8869 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8870 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8871 | secinfo = &flavors->flavors[i]; |
| 8872 | |
| 8873 | switch (secinfo->flavor) { |
| 8874 | case RPC_AUTH_NULL: |
| 8875 | case RPC_AUTH_UNIX: |
| 8876 | case RPC_AUTH_GSS: |
| 8877 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8878 | &secinfo->flavor_info); |
| 8879 | break; |
| 8880 | default: |
| 8881 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8882 | break; |
| 8883 | } |
| 8884 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8885 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8886 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8887 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8888 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8889 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8890 | info, flavor); |
| 8891 | if (!err) |
| 8892 | break; |
| 8893 | } |
| 8894 | } |
| 8895 | |
| 8896 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8897 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8898 | |
| 8899 | out_freepage: |
| 8900 | put_page(page); |
| 8901 | if (err == -EACCES) |
| 8902 | return -EPERM; |
| 8903 | out: |
| 8904 | return err; |
| 8905 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8906 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8907 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8908 | nfs4_stateid *stateid, |
| 8909 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8910 | { |
| 8911 | int status; |
| 8912 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8913 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8914 | }; |
| 8915 | struct nfs41_test_stateid_res res; |
| 8916 | struct rpc_message msg = { |
| 8917 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8918 | .rpc_argp = &args, |
| 8919 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8920 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8921 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8922 | struct rpc_clnt *rpc_client = server->client; |
| 8923 | |
| 8924 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8925 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8926 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8927 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8928 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8929 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8930 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8931 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8932 | if (status != NFS_OK) { |
| 8933 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8934 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8935 | } |
| 8936 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8937 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8938 | } |
| 8939 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8940 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8941 | int err, struct nfs4_exception *exception) |
| 8942 | { |
| 8943 | exception->retry = 0; |
| 8944 | switch(err) { |
| 8945 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8946 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8947 | nfs4_handle_exception(server, err, exception); |
| 8948 | break; |
| 8949 | case -NFS4ERR_BADSESSION: |
| 8950 | case -NFS4ERR_BADSLOT: |
| 8951 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8952 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8953 | case -NFS4ERR_DEADSESSION: |
| 8954 | nfs4_do_handle_exception(server, err, exception); |
| 8955 | } |
| 8956 | } |
| 8957 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8958 | /** |
| 8959 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8960 | * |
| 8961 | * @server: server / transport on which to perform the operation |
| 8962 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8963 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8964 | * |
| 8965 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8966 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8967 | * failed or the state ID is not currently valid. |
| 8968 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8969 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8970 | nfs4_stateid *stateid, |
| 8971 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8972 | { |
| 8973 | struct nfs4_exception exception = { }; |
| 8974 | int err; |
| 8975 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8976 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8977 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8978 | } while (exception.retry); |
| 8979 | return err; |
| 8980 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8981 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8982 | struct nfs_free_stateid_data { |
| 8983 | struct nfs_server *server; |
| 8984 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8985 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8986 | }; |
| 8987 | |
| 8988 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8989 | { |
| 8990 | struct nfs_free_stateid_data *data = calldata; |
| 8991 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8992 | &data->args.seq_args, |
| 8993 | &data->res.seq_res, |
| 8994 | task); |
| 8995 | } |
| 8996 | |
| 8997 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8998 | { |
| 8999 | struct nfs_free_stateid_data *data = calldata; |
| 9000 | |
| 9001 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9002 | |
| 9003 | switch (task->tk_status) { |
| 9004 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9005 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9006 | rpc_restart_call_prepare(task); |
| 9007 | } |
| 9008 | } |
| 9009 | |
| 9010 | static void nfs41_free_stateid_release(void *calldata) |
| 9011 | { |
| 9012 | kfree(calldata); |
| 9013 | } |
| 9014 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9015 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9016 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9017 | .rpc_call_done = nfs41_free_stateid_done, |
| 9018 | .rpc_release = nfs41_free_stateid_release, |
| 9019 | }; |
| 9020 | |
| 9021 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9022 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9023 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9024 | bool privileged) |
| 9025 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9026 | struct rpc_message msg = { |
| 9027 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9028 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9029 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9030 | struct rpc_task_setup task_setup = { |
| 9031 | .rpc_client = server->client, |
| 9032 | .rpc_message = &msg, |
| 9033 | .callback_ops = &nfs41_free_stateid_ops, |
| 9034 | .flags = RPC_TASK_ASYNC, |
| 9035 | }; |
| 9036 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9037 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9038 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9039 | &task_setup.rpc_client, &msg); |
| 9040 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9041 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9042 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9043 | if (!data) |
| 9044 | return ERR_PTR(-ENOMEM); |
| 9045 | data->server = server; |
| 9046 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9047 | |
| 9048 | task_setup.callback_data = data; |
| 9049 | |
| 9050 | msg.rpc_argp = &data->args; |
| 9051 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9052 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9053 | if (privileged) |
| 9054 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9055 | |
| 9056 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9057 | } |
| 9058 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9059 | /** |
| 9060 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9061 | * |
| 9062 | * @server: server / transport on which to perform the operation |
| 9063 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9064 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9065 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9066 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9067 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9068 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9069 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9070 | const nfs4_stateid *stateid, |
| 9071 | struct rpc_cred *cred, |
| 9072 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9073 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9074 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9075 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9076 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9077 | if (IS_ERR(task)) |
| 9078 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9079 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9080 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9081 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9082 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9083 | static void |
| 9084 | 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] | 9085 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9086 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9087 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9088 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9089 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9090 | } |
| 9091 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9092 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9093 | const nfs4_stateid *s2) |
| 9094 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9095 | if (s1->type != s2->type) |
| 9096 | return false; |
| 9097 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9098 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9099 | return false; |
| 9100 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9101 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9102 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9103 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9104 | return true; |
| 9105 | |
| 9106 | return false; |
| 9107 | } |
| 9108 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9109 | #endif /* CONFIG_NFS_V4_1 */ |
| 9110 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9111 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9112 | const nfs4_stateid *s2) |
| 9113 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9114 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9115 | } |
| 9116 | |
| 9117 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9118 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9119 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9120 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9121 | .recover_open = nfs4_open_reclaim, |
| 9122 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9123 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9124 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9125 | }; |
| 9126 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9127 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9128 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9129 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9130 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9131 | .recover_open = nfs4_open_reclaim, |
| 9132 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9133 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9134 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9135 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9136 | }; |
| 9137 | #endif /* CONFIG_NFS_V4_1 */ |
| 9138 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9139 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9140 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9141 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9142 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9143 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9144 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9145 | }; |
| 9146 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9147 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9148 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9149 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9150 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9151 | .recover_open = nfs41_open_expired, |
| 9152 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9153 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9154 | }; |
| 9155 | #endif /* CONFIG_NFS_V4_1 */ |
| 9156 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9157 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9158 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9159 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9160 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9161 | }; |
| 9162 | |
| 9163 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9164 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9165 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9166 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9167 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9168 | }; |
| 9169 | #endif |
| 9170 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9171 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9172 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9173 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9174 | }; |
| 9175 | |
| 9176 | #if defined(CONFIG_NFS_V4_1) |
| 9177 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9178 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9179 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9180 | }; |
| 9181 | #endif /* CONFIG_NFS_V4_1 */ |
| 9182 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9183 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9184 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9185 | .init_caps = NFS_CAP_READDIRPLUS |
| 9186 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9187 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9188 | .init_client = nfs40_init_client, |
| 9189 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9190 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9191 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9192 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9193 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9194 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9195 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9196 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9197 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9198 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9199 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9200 | }; |
| 9201 | |
| 9202 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9203 | static struct nfs_seqid * |
| 9204 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9205 | { |
| 9206 | return NULL; |
| 9207 | } |
| 9208 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9209 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9210 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9211 | .init_caps = NFS_CAP_READDIRPLUS |
| 9212 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9213 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9214 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9215 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9216 | .init_client = nfs41_init_client, |
| 9217 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9218 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9219 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9220 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9221 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9222 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9223 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9224 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9225 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9226 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9227 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9228 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9229 | }; |
| 9230 | #endif |
| 9231 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9232 | #if defined(CONFIG_NFS_V4_2) |
| 9233 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9234 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9235 | .init_caps = NFS_CAP_READDIRPLUS |
| 9236 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9237 | | NFS_CAP_POSIX_LOCK |
| 9238 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9239 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9240 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9241 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9242 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9243 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9244 | | NFS_CAP_LAYOUTSTATS |
| 9245 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9246 | .init_client = nfs41_init_client, |
| 9247 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9248 | .match_stateid = nfs41_match_stateid, |
| 9249 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9250 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9251 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9252 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9253 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9254 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9255 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9256 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9257 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9258 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9259 | }; |
| 9260 | #endif |
| 9261 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9262 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9263 | [0] = &nfs_v4_0_minor_ops, |
| 9264 | #if defined(CONFIG_NFS_V4_1) |
| 9265 | [1] = &nfs_v4_1_minor_ops, |
| 9266 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9267 | #if defined(CONFIG_NFS_V4_2) |
| 9268 | [2] = &nfs_v4_2_minor_ops, |
| 9269 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9270 | }; |
| 9271 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9272 | 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] | 9273 | { |
| 9274 | ssize_t error, error2; |
| 9275 | |
| 9276 | error = generic_listxattr(dentry, list, size); |
| 9277 | if (error < 0) |
| 9278 | return error; |
| 9279 | if (list) { |
| 9280 | list += error; |
| 9281 | size -= error; |
| 9282 | } |
| 9283 | |
| 9284 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9285 | if (error2 < 0) |
| 9286 | return error2; |
| 9287 | return error + error2; |
| 9288 | } |
| 9289 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9290 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9291 | .create = nfs_create, |
| 9292 | .lookup = nfs_lookup, |
| 9293 | .atomic_open = nfs_atomic_open, |
| 9294 | .link = nfs_link, |
| 9295 | .unlink = nfs_unlink, |
| 9296 | .symlink = nfs_symlink, |
| 9297 | .mkdir = nfs_mkdir, |
| 9298 | .rmdir = nfs_rmdir, |
| 9299 | .mknod = nfs_mknod, |
| 9300 | .rename = nfs_rename, |
| 9301 | .permission = nfs_permission, |
| 9302 | .getattr = nfs_getattr, |
| 9303 | .setattr = nfs_setattr, |
| 9304 | .getxattr = generic_getxattr, |
| 9305 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9306 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9307 | .removexattr = generic_removexattr, |
| 9308 | }; |
| 9309 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9310 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9311 | .permission = nfs_permission, |
| 9312 | .getattr = nfs_getattr, |
| 9313 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9314 | .getxattr = generic_getxattr, |
| 9315 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9316 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9317 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9318 | }; |
| 9319 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9320 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9321 | .version = 4, /* protocol version */ |
| 9322 | .dentry_ops = &nfs4_dentry_operations, |
| 9323 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9324 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9325 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9326 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9327 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9328 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9329 | .getattr = nfs4_proc_getattr, |
| 9330 | .setattr = nfs4_proc_setattr, |
| 9331 | .lookup = nfs4_proc_lookup, |
| 9332 | .access = nfs4_proc_access, |
| 9333 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9334 | .create = nfs4_proc_create, |
| 9335 | .remove = nfs4_proc_remove, |
| 9336 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9337 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9338 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9339 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9340 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9341 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9342 | .link = nfs4_proc_link, |
| 9343 | .symlink = nfs4_proc_symlink, |
| 9344 | .mkdir = nfs4_proc_mkdir, |
| 9345 | .rmdir = nfs4_proc_remove, |
| 9346 | .readdir = nfs4_proc_readdir, |
| 9347 | .mknod = nfs4_proc_mknod, |
| 9348 | .statfs = nfs4_proc_statfs, |
| 9349 | .fsinfo = nfs4_proc_fsinfo, |
| 9350 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9351 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9352 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9353 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9354 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9355 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9356 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9357 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9358 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9359 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9360 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9361 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9362 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9363 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9364 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9365 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9366 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9367 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9368 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9369 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9370 | .create_server = nfs4_create_server, |
| 9371 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9372 | }; |
| 9373 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9374 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9375 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9376 | .list = nfs4_xattr_list_nfs4_acl, |
| 9377 | .get = nfs4_xattr_get_nfs4_acl, |
| 9378 | .set = nfs4_xattr_set_nfs4_acl, |
| 9379 | }; |
| 9380 | |
| 9381 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9382 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9383 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9384 | &nfs4_xattr_nfs4_label_handler, |
| 9385 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9386 | NULL |
| 9387 | }; |
| 9388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9389 | /* |
| 9390 | * Local variables: |
| 9391 | * c-basic-offset: 8 |
| 9392 | * End: |
| 9393 | */ |