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 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 81 | static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *, struct nfs4_state *, long *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 83 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 84 | 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] | 85 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 86 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 87 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 88 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 90 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 91 | struct rpc_cred *); |
| 92 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 93 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 94 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 97 | static inline struct nfs4_label * |
| 98 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 99 | struct iattr *sattr, struct nfs4_label *label) |
| 100 | { |
| 101 | int err; |
| 102 | |
| 103 | if (label == NULL) |
| 104 | return NULL; |
| 105 | |
| 106 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 107 | return NULL; |
| 108 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 110 | &dentry->d_name, (void **)&label->label, &label->len); |
| 111 | if (err == 0) |
| 112 | return label; |
| 113 | |
| 114 | return NULL; |
| 115 | } |
| 116 | static inline void |
| 117 | nfs4_label_release_security(struct nfs4_label *label) |
| 118 | { |
| 119 | if (label) |
| 120 | security_release_secctx(label->label, label->len); |
| 121 | } |
| 122 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 123 | { |
| 124 | if (label) |
| 125 | return server->attr_bitmask; |
| 126 | |
| 127 | return server->attr_bitmask_nl; |
| 128 | } |
| 129 | #else |
| 130 | static inline struct nfs4_label * |
| 131 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 132 | struct iattr *sattr, struct nfs4_label *l) |
| 133 | { return NULL; } |
| 134 | static inline void |
| 135 | nfs4_label_release_security(struct nfs4_label *label) |
| 136 | { return; } |
| 137 | static inline u32 * |
| 138 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 139 | { return server->attr_bitmask; } |
| 140 | #endif |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 143 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 145 | if (err >= -1000) |
| 146 | return err; |
| 147 | switch (err) { |
| 148 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 149 | case -NFS4ERR_LAYOUTTRYLATER: |
| 150 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 151 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 152 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 153 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 155 | case -NFS4ERR_BADOWNER: |
| 156 | case -NFS4ERR_BADNAME: |
| 157 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 158 | case -NFS4ERR_SHARE_DENIED: |
| 159 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 160 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 161 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 162 | case -NFS4ERR_FILE_OPEN: |
| 163 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 166 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 169 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* |
| 173 | * This is our standard bitmap for GETATTR requests. |
| 174 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 175 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | FATTR4_WORD0_TYPE |
| 177 | | FATTR4_WORD0_CHANGE |
| 178 | | FATTR4_WORD0_SIZE |
| 179 | | FATTR4_WORD0_FSID |
| 180 | | FATTR4_WORD0_FILEID, |
| 181 | FATTR4_WORD1_MODE |
| 182 | | FATTR4_WORD1_NUMLINKS |
| 183 | | FATTR4_WORD1_OWNER |
| 184 | | FATTR4_WORD1_OWNER_GROUP |
| 185 | | FATTR4_WORD1_RAWDEV |
| 186 | | FATTR4_WORD1_SPACE_USED |
| 187 | | FATTR4_WORD1_TIME_ACCESS |
| 188 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 189 | | FATTR4_WORD1_TIME_MODIFY |
| 190 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 191 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 192 | FATTR4_WORD2_SECURITY_LABEL |
| 193 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 196 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 197 | FATTR4_WORD0_TYPE |
| 198 | | FATTR4_WORD0_CHANGE |
| 199 | | FATTR4_WORD0_SIZE |
| 200 | | FATTR4_WORD0_FSID |
| 201 | | FATTR4_WORD0_FILEID, |
| 202 | FATTR4_WORD1_MODE |
| 203 | | FATTR4_WORD1_NUMLINKS |
| 204 | | FATTR4_WORD1_OWNER |
| 205 | | FATTR4_WORD1_OWNER_GROUP |
| 206 | | FATTR4_WORD1_RAWDEV |
| 207 | | FATTR4_WORD1_SPACE_USED |
| 208 | | FATTR4_WORD1_TIME_ACCESS |
| 209 | | FATTR4_WORD1_TIME_METADATA |
| 210 | | FATTR4_WORD1_TIME_MODIFY, |
| 211 | FATTR4_WORD2_MDSTHRESHOLD |
| 212 | }; |
| 213 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 214 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 215 | FATTR4_WORD0_TYPE |
| 216 | | FATTR4_WORD0_CHANGE |
| 217 | | FATTR4_WORD0_FILEID, |
| 218 | }; |
| 219 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 220 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | FATTR4_WORD0_FILES_AVAIL |
| 222 | | FATTR4_WORD0_FILES_FREE |
| 223 | | FATTR4_WORD0_FILES_TOTAL, |
| 224 | FATTR4_WORD1_SPACE_AVAIL |
| 225 | | FATTR4_WORD1_SPACE_FREE |
| 226 | | FATTR4_WORD1_SPACE_TOTAL |
| 227 | }; |
| 228 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 229 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | FATTR4_WORD0_MAXLINK |
| 231 | | FATTR4_WORD0_MAXNAME, |
| 232 | 0 |
| 233 | }; |
| 234 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 235 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | | FATTR4_WORD0_MAXREAD |
| 237 | | FATTR4_WORD0_MAXWRITE |
| 238 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 239 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 240 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 241 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 245 | FATTR4_WORD0_TYPE |
| 246 | | FATTR4_WORD0_CHANGE |
| 247 | | FATTR4_WORD0_SIZE |
| 248 | | FATTR4_WORD0_FSID |
| 249 | | FATTR4_WORD0_FILEID |
| 250 | | FATTR4_WORD0_FS_LOCATIONS, |
| 251 | FATTR4_WORD1_MODE |
| 252 | | FATTR4_WORD1_NUMLINKS |
| 253 | | FATTR4_WORD1_OWNER |
| 254 | | FATTR4_WORD1_OWNER_GROUP |
| 255 | | FATTR4_WORD1_RAWDEV |
| 256 | | FATTR4_WORD1_SPACE_USED |
| 257 | | FATTR4_WORD1_TIME_ACCESS |
| 258 | | FATTR4_WORD1_TIME_METADATA |
| 259 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 263 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct nfs4_readdir_arg *readdir) |
| 265 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 266 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 269 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | readdir->cookie = 0; |
| 275 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 276 | if (cookie == 2) |
| 277 | return; |
| 278 | |
| 279 | /* |
| 280 | * NFSv4 servers do not return entries for '.' and '..' |
| 281 | * Therefore, we fake these entries here. We let '.' |
| 282 | * have cookie 0 and '..' have cookie 1. Note that |
| 283 | * when talking to the server, we always send cookie 0 |
| 284 | * instead of 1 or 2. |
| 285 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 286 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (cookie == 0) { |
| 289 | *p++ = xdr_one; /* next */ |
| 290 | *p++ = xdr_zero; /* cookie, first word */ |
| 291 | *p++ = xdr_one; /* cookie, second word */ |
| 292 | *p++ = xdr_one; /* entry len */ |
| 293 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 294 | p++; |
| 295 | *p++ = xdr_one; /* bitmap length */ |
| 296 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 297 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 298 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_two; /* cookie, second word */ |
| 304 | *p++ = xdr_two; /* entry len */ |
| 305 | memcpy(p, "..\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | readdir->pgbase = (char *)p - (char *)start; |
| 313 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 314 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 317 | static long nfs4_update_delay(long *timeout) |
| 318 | { |
| 319 | long ret; |
| 320 | if (!timeout) |
| 321 | return NFS4_POLL_RETRY_MAX; |
| 322 | if (*timeout <= 0) |
| 323 | *timeout = NFS4_POLL_RETRY_MIN; |
| 324 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 325 | *timeout = NFS4_POLL_RETRY_MAX; |
| 326 | ret = *timeout; |
| 327 | *timeout <<= 1; |
| 328 | return ret; |
| 329 | } |
| 330 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 331 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 332 | { |
| 333 | int res = 0; |
| 334 | |
| 335 | might_sleep(); |
| 336 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 337 | freezable_schedule_timeout_killable_unsafe( |
| 338 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | if (fatal_signal_pending(current)) |
| 340 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | return res; |
| 342 | } |
| 343 | |
| 344 | /* This is the error handling routine for processes that are allowed |
| 345 | * to sleep. |
| 346 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 347 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 348 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | { |
| 350 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 351 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 352 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | int ret = errorcode; |
| 354 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 355 | exception->delay = 0; |
| 356 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 357 | exception->retry = 0; |
| 358 | switch(errorcode) { |
| 359 | case 0: |
| 360 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 361 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 362 | case -NFS4ERR_DELEG_REVOKED: |
| 363 | case -NFS4ERR_ADMIN_REVOKED: |
| 364 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 4816fda | 2015-09-20 14:58:42 -0400 | [diff] [blame^] | 365 | if (inode && nfs_async_inode_return_delegation(inode, |
| 366 | NULL) == 0) |
| 367 | goto wait_on_recovery; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 368 | if (state == NULL) |
| 369 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 370 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 371 | if (ret < 0) |
| 372 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 373 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 374 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 375 | if (state != NULL) { |
| 376 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 377 | if (ret < 0) |
| 378 | break; |
| 379 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 381 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 382 | nfs4_schedule_lease_recovery(clp); |
| 383 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 384 | case -NFS4ERR_MOVED: |
| 385 | ret = nfs4_schedule_migration_recovery(server); |
| 386 | if (ret < 0) |
| 387 | break; |
| 388 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 389 | case -NFS4ERR_LEASE_MOVED: |
| 390 | nfs4_schedule_lease_moved_recovery(clp); |
| 391 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 392 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 393 | case -NFS4ERR_BADSESSION: |
| 394 | case -NFS4ERR_BADSLOT: |
| 395 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 396 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 397 | case -NFS4ERR_DEADSESSION: |
| 398 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 399 | case -NFS4ERR_SEQ_MISORDERED: |
| 400 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 401 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 402 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 403 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 404 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 405 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 406 | if (exception->timeout > HZ) { |
| 407 | /* We have retried a decent amount, time to |
| 408 | * fail |
| 409 | */ |
| 410 | ret = -EBUSY; |
| 411 | break; |
| 412 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 414 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 415 | case -NFS4ERR_GRACE: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 416 | exception->delay = 1; |
| 417 | return 0; |
| 418 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 419 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 420 | case -NFS4ERR_OLD_STATEID: |
| 421 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 422 | break; |
| 423 | case -NFS4ERR_BADOWNER: |
| 424 | /* The following works around a Linux server bug! */ |
| 425 | case -NFS4ERR_BADNAME: |
| 426 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 427 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 428 | exception->retry = 1; |
| 429 | printk(KERN_WARNING "NFS: v4 server %s " |
| 430 | "does not accept raw " |
| 431 | "uid/gids. " |
| 432 | "Reenabling the idmapper.\n", |
| 433 | server->nfs_client->cl_hostname); |
| 434 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | } |
| 436 | /* We failed to handle the error */ |
| 437 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 438 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 439 | exception->recovering = 1; |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | /* This is the error handling routine for processes that are allowed |
| 444 | * to sleep. |
| 445 | */ |
| 446 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 447 | { |
| 448 | struct nfs_client *clp = server->nfs_client; |
| 449 | int ret; |
| 450 | |
| 451 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 452 | if (exception->delay) { |
| 453 | ret = nfs4_delay(server->client, &exception->timeout); |
| 454 | goto out_retry; |
| 455 | } |
| 456 | if (exception->recovering) { |
| 457 | ret = nfs4_wait_clnt_recover(clp); |
| 458 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 459 | return -EIO; |
| 460 | goto out_retry; |
| 461 | } |
| 462 | return ret; |
| 463 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 464 | if (ret == 0) |
| 465 | exception->retry = 1; |
| 466 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 467 | } |
| 468 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 469 | /* |
| 470 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 471 | * or 'false' otherwise. |
| 472 | */ |
| 473 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 474 | { |
| 475 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 476 | |
| 477 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 478 | flavor == RPC_AUTH_GSS_KRB5P) |
| 479 | return true; |
| 480 | |
| 481 | return false; |
| 482 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 483 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 484 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | spin_lock(&clp->cl_lock); |
| 487 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 488 | clp->cl_last_renewal = timestamp; |
| 489 | spin_unlock(&clp->cl_lock); |
| 490 | } |
| 491 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 492 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 493 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 494 | struct nfs_client *clp = server->nfs_client; |
| 495 | |
| 496 | if (!nfs4_has_session(clp)) |
| 497 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 500 | struct nfs4_call_sync_data { |
| 501 | const struct nfs_server *seq_server; |
| 502 | struct nfs4_sequence_args *seq_args; |
| 503 | struct nfs4_sequence_res *seq_res; |
| 504 | }; |
| 505 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 506 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 507 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 508 | { |
| 509 | args->sa_slot = NULL; |
| 510 | args->sa_cache_this = cache_reply; |
| 511 | args->sa_privileged = 0; |
| 512 | |
| 513 | res->sr_slot = NULL; |
| 514 | } |
| 515 | |
| 516 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 517 | { |
| 518 | args->sa_privileged = 1; |
| 519 | } |
| 520 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 521 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 522 | struct nfs4_sequence_args *args, |
| 523 | struct nfs4_sequence_res *res, |
| 524 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 525 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 526 | struct nfs4_slot *slot; |
| 527 | |
| 528 | /* slot already allocated? */ |
| 529 | if (res->sr_slot != NULL) |
| 530 | goto out_start; |
| 531 | |
| 532 | spin_lock(&tbl->slot_tbl_lock); |
| 533 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 534 | goto out_sleep; |
| 535 | |
| 536 | slot = nfs4_alloc_slot(tbl); |
| 537 | if (IS_ERR(slot)) { |
| 538 | if (slot == ERR_PTR(-ENOMEM)) |
| 539 | task->tk_timeout = HZ >> 2; |
| 540 | goto out_sleep; |
| 541 | } |
| 542 | spin_unlock(&tbl->slot_tbl_lock); |
| 543 | |
| 544 | args->sa_slot = slot; |
| 545 | res->sr_slot = slot; |
| 546 | |
| 547 | out_start: |
| 548 | rpc_call_start(task); |
| 549 | return 0; |
| 550 | |
| 551 | out_sleep: |
| 552 | if (args->sa_privileged) |
| 553 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 554 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 555 | else |
| 556 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 557 | spin_unlock(&tbl->slot_tbl_lock); |
| 558 | return -EAGAIN; |
| 559 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 560 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 561 | |
| 562 | static int nfs40_sequence_done(struct rpc_task *task, |
| 563 | struct nfs4_sequence_res *res) |
| 564 | { |
| 565 | struct nfs4_slot *slot = res->sr_slot; |
| 566 | struct nfs4_slot_table *tbl; |
| 567 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 568 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 569 | goto out; |
| 570 | |
| 571 | tbl = slot->table; |
| 572 | spin_lock(&tbl->slot_tbl_lock); |
| 573 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 574 | nfs4_free_slot(tbl, slot); |
| 575 | spin_unlock(&tbl->slot_tbl_lock); |
| 576 | |
| 577 | res->sr_slot = NULL; |
| 578 | out: |
| 579 | return 1; |
| 580 | } |
| 581 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 582 | #if defined(CONFIG_NFS_V4_1) |
| 583 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 584 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 585 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 586 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 587 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 588 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 589 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 590 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 591 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 592 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 593 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 594 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 595 | /* Be nice to the server: try to ensure that the last transmitted |
| 596 | * value for highest_user_slotid <= target_highest_slotid |
| 597 | */ |
| 598 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 599 | send_new_highest_used_slotid = true; |
| 600 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 601 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 602 | send_new_highest_used_slotid = false; |
| 603 | goto out_unlock; |
| 604 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 605 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 606 | |
| 607 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 608 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 609 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 610 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 611 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 612 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 613 | nfs41_notify_server(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 616 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 617 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 618 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 619 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 620 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 621 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 622 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 623 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 624 | if (slot == NULL) |
| 625 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 626 | /* don't increment the sequence number if the task wasn't sent */ |
| 627 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 628 | goto out; |
| 629 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 630 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 631 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 632 | if (slot->interrupted) { |
| 633 | slot->interrupted = 0; |
| 634 | interrupted = true; |
| 635 | } |
| 636 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 637 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 638 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 639 | switch (res->sr_status) { |
| 640 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 641 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 642 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 643 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 644 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 645 | /* Check sequence flags */ |
Trond Myklebust | b15c7cd | 2015-07-05 15:01:36 -0400 | [diff] [blame] | 646 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 647 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 648 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 649 | case 1: |
| 650 | /* |
| 651 | * sr_status remains 1 if an RPC level error occurred. |
| 652 | * The server may or may not have processed the sequence |
| 653 | * operation.. |
| 654 | * Mark the slot as having hosted an interrupted RPC call. |
| 655 | */ |
| 656 | slot->interrupted = 1; |
| 657 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 658 | case -NFS4ERR_DELAY: |
| 659 | /* The server detected a resend of the RPC call and |
| 660 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 661 | * of RFC5661. |
| 662 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 663 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 664 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 665 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 666 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 667 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 668 | case -NFS4ERR_BADSLOT: |
| 669 | /* |
| 670 | * The slot id we used was probably retired. Try again |
| 671 | * using a different slot id. |
| 672 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 673 | goto retry_nowait; |
| 674 | case -NFS4ERR_SEQ_MISORDERED: |
| 675 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 676 | * Was the last operation on this sequence interrupted? |
| 677 | * If so, retry after bumping the sequence number. |
| 678 | */ |
| 679 | if (interrupted) { |
| 680 | ++slot->seq_nr; |
| 681 | goto retry_nowait; |
| 682 | } |
| 683 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 684 | * Could this slot have been previously retired? |
| 685 | * If so, then the server may be expecting seq_nr = 1! |
| 686 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 687 | if (slot->seq_nr != 1) { |
| 688 | slot->seq_nr = 1; |
| 689 | goto retry_nowait; |
| 690 | } |
| 691 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 692 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 693 | ++slot->seq_nr; |
| 694 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 695 | default: |
| 696 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 697 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 698 | } |
| 699 | out: |
| 700 | /* The session may be reset by one of the error handlers. */ |
| 701 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 702 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 703 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 704 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 705 | retry_nowait: |
| 706 | if (rpc_restart_call_prepare(task)) { |
| 707 | task->tk_status = 0; |
| 708 | ret = 0; |
| 709 | } |
| 710 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 712 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 713 | goto out; |
| 714 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 715 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 716 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 717 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 718 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 719 | 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] | 720 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 721 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 722 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 723 | if (!res->sr_slot->table->session) |
| 724 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 725 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 726 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 727 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 728 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 729 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | struct nfs4_sequence_args *args, |
| 731 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 732 | struct rpc_task *task) |
| 733 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 734 | struct nfs4_slot *slot; |
| 735 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 736 | |
| 737 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 738 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 739 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 740 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 741 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 742 | tbl = &session->fc_slot_table; |
| 743 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 744 | task->tk_timeout = 0; |
| 745 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 746 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 747 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 748 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 749 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 750 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 751 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 752 | } |
| 753 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 754 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 755 | if (IS_ERR(slot)) { |
| 756 | /* If out of memory, try again in 1/4 second */ |
| 757 | if (slot == ERR_PTR(-ENOMEM)) |
| 758 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 759 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 760 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 761 | } |
| 762 | spin_unlock(&tbl->slot_tbl_lock); |
| 763 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 764 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 765 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 766 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 767 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 768 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 769 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 770 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 771 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 772 | /* |
| 773 | * sr_status is only set in decode_sequence, and so will remain |
| 774 | * set to 1 if an rpc level failure occurs. |
| 775 | */ |
| 776 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 777 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 778 | out_success: |
| 779 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 780 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 781 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 782 | /* Privileged tasks are queued with top priority */ |
| 783 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 784 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 785 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 786 | else |
| 787 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 788 | spin_unlock(&tbl->slot_tbl_lock); |
| 789 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 790 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 791 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 792 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 793 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 794 | struct nfs4_sequence_args *args, |
| 795 | struct nfs4_sequence_res *res, |
| 796 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 797 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 798 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 799 | int ret = 0; |
| 800 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 801 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 802 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 803 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 804 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 805 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 806 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 807 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 809 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 810 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 811 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 812 | return ret; |
| 813 | } |
| 814 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 815 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 816 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 817 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 818 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 819 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 820 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 821 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 822 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 825 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 826 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 827 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 828 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 832 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 833 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 834 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 835 | }; |
| 836 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 837 | #else /* !CONFIG_NFS_V4_1 */ |
| 838 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 839 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 840 | struct nfs4_sequence_args *args, |
| 841 | struct nfs4_sequence_res *res, |
| 842 | struct rpc_task *task) |
| 843 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 844 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 845 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 846 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 847 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 848 | int nfs4_sequence_done(struct rpc_task *task, |
| 849 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 850 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 851 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 852 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 853 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 854 | |
| 855 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 856 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 857 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 858 | { |
| 859 | struct nfs4_call_sync_data *data = calldata; |
| 860 | nfs4_setup_sequence(data->seq_server, |
| 861 | data->seq_args, data->seq_res, task); |
| 862 | } |
| 863 | |
| 864 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 865 | { |
| 866 | struct nfs4_call_sync_data *data = calldata; |
| 867 | nfs4_sequence_done(task, data->seq_res); |
| 868 | } |
| 869 | |
| 870 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 871 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 872 | .rpc_call_done = nfs40_call_sync_done, |
| 873 | }; |
| 874 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 875 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 876 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 877 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 878 | struct nfs4_sequence_args *args, |
| 879 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 880 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 881 | int ret; |
| 882 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 883 | struct nfs_client *clp = server->nfs_client; |
| 884 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | .seq_server = server, |
| 886 | .seq_args = args, |
| 887 | .seq_res = res, |
| 888 | }; |
| 889 | struct rpc_task_setup task_setup = { |
| 890 | .rpc_client = clnt, |
| 891 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 892 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | .callback_data = &data |
| 894 | }; |
| 895 | |
| 896 | task = rpc_run_task(&task_setup); |
| 897 | if (IS_ERR(task)) |
| 898 | ret = PTR_ERR(task); |
| 899 | else { |
| 900 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 901 | rpc_put_task(task); |
| 902 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 903 | return ret; |
| 904 | } |
| 905 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 906 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 907 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 908 | struct rpc_message *msg, |
| 909 | struct nfs4_sequence_args *args, |
| 910 | struct nfs4_sequence_res *res, |
| 911 | int cache_reply) |
| 912 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 913 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 914 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 918 | { |
| 919 | struct nfs_inode *nfsi = NFS_I(dir); |
| 920 | |
| 921 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 922 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 923 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 925 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 926 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 927 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | spin_unlock(&dir->i_lock); |
| 929 | } |
| 930 | |
| 931 | struct nfs4_opendata { |
| 932 | struct kref kref; |
| 933 | struct nfs_openargs o_arg; |
| 934 | struct nfs_openres o_res; |
| 935 | struct nfs_open_confirmargs c_arg; |
| 936 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 937 | struct nfs4_string owner_name; |
| 938 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 939 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 941 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 943 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | struct nfs4_state_owner *owner; |
| 945 | struct nfs4_state *state; |
| 946 | struct iattr attrs; |
| 947 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 948 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 949 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 950 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 951 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | int cancelled; |
| 953 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 954 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 955 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 956 | int err, struct nfs4_exception *exception) |
| 957 | { |
| 958 | if (err != -EINVAL) |
| 959 | return false; |
| 960 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 961 | return false; |
| 962 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 963 | exception->retry = 1; |
| 964 | return true; |
| 965 | } |
| 966 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 967 | static u32 |
| 968 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 969 | fmode_t fmode, int openflags) |
| 970 | { |
| 971 | u32 res = 0; |
| 972 | |
| 973 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 974 | case FMODE_READ: |
| 975 | res = NFS4_SHARE_ACCESS_READ; |
| 976 | break; |
| 977 | case FMODE_WRITE: |
| 978 | res = NFS4_SHARE_ACCESS_WRITE; |
| 979 | break; |
| 980 | case FMODE_READ|FMODE_WRITE: |
| 981 | res = NFS4_SHARE_ACCESS_BOTH; |
| 982 | } |
| 983 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 984 | goto out; |
| 985 | /* Want no delegation if we're using O_DIRECT */ |
| 986 | if (openflags & O_DIRECT) |
| 987 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 988 | out: |
| 989 | return res; |
| 990 | } |
| 991 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 992 | static enum open_claim_type4 |
| 993 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 994 | enum open_claim_type4 claim) |
| 995 | { |
| 996 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 997 | return claim; |
| 998 | switch (claim) { |
| 999 | default: |
| 1000 | return claim; |
| 1001 | case NFS4_OPEN_CLAIM_FH: |
| 1002 | return NFS4_OPEN_CLAIM_NULL; |
| 1003 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1004 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1005 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1006 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1007 | } |
| 1008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
| 1010 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1011 | { |
| 1012 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1013 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1014 | p->o_res.seqid = p->o_arg.seqid; |
| 1015 | p->c_res.seqid = p->c_arg.seqid; |
| 1016 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1017 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1018 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1019 | 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] | 1020 | } |
| 1021 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1022 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1023 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1024 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1025 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1026 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1027 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1028 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1029 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1030 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1031 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1032 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1033 | struct nfs4_opendata *p; |
| 1034 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1035 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1036 | if (p == NULL) |
| 1037 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1038 | |
| 1039 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1040 | if (IS_ERR(p->f_label)) |
| 1041 | goto err_free_p; |
| 1042 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1043 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1044 | if (IS_ERR(p->a_label)) |
| 1045 | goto err_free_f; |
| 1046 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1047 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1048 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1049 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1050 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1051 | nfs_sb_active(dentry->d_sb); |
| 1052 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1053 | p->dir = parent; |
| 1054 | p->owner = sp; |
| 1055 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | p->o_arg.open_flags = flags; |
| 1057 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1058 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1059 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1060 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1061 | * will return permission denied for all bits until close */ |
| 1062 | if (!(flags & O_EXCL)) { |
| 1063 | /* ask server to check for all possible rights as results |
| 1064 | * are cached */ |
| 1065 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1066 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1067 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1068 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1069 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1070 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1071 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1072 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1073 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1074 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1075 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1076 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1077 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1078 | case NFS4_OPEN_CLAIM_NULL: |
| 1079 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1080 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1081 | p->o_arg.fh = NFS_FH(dir); |
| 1082 | break; |
| 1083 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1084 | case NFS4_OPEN_CLAIM_FH: |
| 1085 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1086 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1087 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1088 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1089 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1090 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1091 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1092 | p->o_arg.u.attrs = &p->attrs; |
| 1093 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1094 | |
| 1095 | verf[0] = jiffies; |
| 1096 | verf[1] = current->pid; |
| 1097 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1098 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1099 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1100 | p->c_arg.fh = &p->o_res.fh; |
| 1101 | p->c_arg.stateid = &p->o_res.stateid; |
| 1102 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1103 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1104 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1105 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1106 | |
| 1107 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1108 | nfs4_label_free(p->a_label); |
| 1109 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1110 | nfs4_label_free(p->f_label); |
| 1111 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1112 | kfree(p); |
| 1113 | err: |
| 1114 | dput(parent); |
| 1115 | return NULL; |
| 1116 | } |
| 1117 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1118 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1119 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1120 | struct nfs4_opendata *p = container_of(kref, |
| 1121 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1122 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1123 | |
| 1124 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1125 | if (p->state != NULL) |
| 1126 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1127 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1128 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1129 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1130 | nfs4_label_free(p->f_label); |
| 1131 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1132 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1133 | dput(p->dentry); |
| 1134 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1135 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1136 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1137 | kfree(p); |
| 1138 | } |
| 1139 | |
| 1140 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1141 | { |
| 1142 | if (p != NULL) |
| 1143 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1146 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1147 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1148 | int ret; |
| 1149 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1150 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1151 | return ret; |
| 1152 | } |
| 1153 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1154 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1155 | fmode_t fmode) |
| 1156 | { |
| 1157 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1158 | case FMODE_READ|FMODE_WRITE: |
| 1159 | return state->n_rdwr != 0; |
| 1160 | case FMODE_WRITE: |
| 1161 | return state->n_wronly != 0; |
| 1162 | case FMODE_READ: |
| 1163 | return state->n_rdonly != 0; |
| 1164 | } |
| 1165 | WARN_ON_ONCE(1); |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1169 | 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] | 1170 | { |
| 1171 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1172 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1173 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1174 | goto out; |
| 1175 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1176 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1177 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1178 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1179 | break; |
| 1180 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1181 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1182 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1183 | break; |
| 1184 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1185 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1186 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1187 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1188 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1189 | return ret; |
| 1190 | } |
| 1191 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1192 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1193 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1194 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1195 | if (delegation == NULL) |
| 1196 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1197 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1198 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1199 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1200 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1201 | switch (claim) { |
| 1202 | case NFS4_OPEN_CLAIM_NULL: |
| 1203 | case NFS4_OPEN_CLAIM_FH: |
| 1204 | break; |
| 1205 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1206 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1207 | break; |
| 1208 | default: |
| 1209 | return 0; |
| 1210 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1211 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1212 | return 1; |
| 1213 | } |
| 1214 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1216 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1217 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1218 | case FMODE_WRITE: |
| 1219 | state->n_wronly++; |
| 1220 | break; |
| 1221 | case FMODE_READ: |
| 1222 | state->n_rdonly++; |
| 1223 | break; |
| 1224 | case FMODE_READ|FMODE_WRITE: |
| 1225 | state->n_rdwr++; |
| 1226 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1227 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1230 | 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] | 1231 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1232 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1233 | bool need_recover = false; |
| 1234 | |
| 1235 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1236 | need_recover = true; |
| 1237 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1238 | need_recover = true; |
| 1239 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1240 | need_recover = true; |
| 1241 | if (need_recover) |
| 1242 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1243 | } |
| 1244 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1245 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1246 | nfs4_stateid *stateid) |
| 1247 | { |
| 1248 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1249 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1250 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1251 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1252 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1253 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1254 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1255 | return true; |
| 1256 | return false; |
| 1257 | } |
| 1258 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1259 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1260 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1261 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1262 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1263 | if (state->n_wronly) |
| 1264 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1265 | if (state->n_rdonly) |
| 1266 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1267 | if (state->n_rdwr) |
| 1268 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1269 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1270 | } |
| 1271 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1272 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1273 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1274 | nfs4_stateid *stateid, fmode_t fmode) |
| 1275 | { |
| 1276 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1277 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1278 | case FMODE_WRITE: |
| 1279 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1280 | break; |
| 1281 | case FMODE_READ: |
| 1282 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1283 | break; |
| 1284 | case 0: |
| 1285 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1286 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1287 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1288 | } |
| 1289 | if (stateid == NULL) |
| 1290 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1291 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1292 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1293 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1294 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1295 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1296 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1297 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1298 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1299 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1300 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1301 | } |
| 1302 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1303 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1304 | nfs4_stateid *arg_stateid, |
| 1305 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1306 | { |
| 1307 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1308 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1309 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1310 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1311 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1312 | } |
| 1313 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1314 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1315 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1316 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1317 | case FMODE_READ: |
| 1318 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1319 | break; |
| 1320 | case FMODE_WRITE: |
| 1321 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1322 | break; |
| 1323 | case FMODE_READ|FMODE_WRITE: |
| 1324 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1325 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1326 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1327 | return; |
| 1328 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1329 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1330 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1331 | } |
| 1332 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1333 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1335 | /* |
| 1336 | * Protect the call to nfs4_state_set_mode_locked and |
| 1337 | * serialise the stateid update |
| 1338 | */ |
| 1339 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1340 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1341 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1342 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1343 | } |
| 1344 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1345 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1346 | write_sequnlock(&state->seqlock); |
| 1347 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1349 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1352 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1353 | { |
| 1354 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1355 | struct nfs_delegation *deleg_cur; |
| 1356 | int ret = 0; |
| 1357 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1358 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1359 | |
| 1360 | rcu_read_lock(); |
| 1361 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1362 | if (deleg_cur == NULL) |
| 1363 | goto no_delegation; |
| 1364 | |
| 1365 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1366 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1367 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1368 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1369 | goto no_delegation_unlock; |
| 1370 | |
| 1371 | if (delegation == NULL) |
| 1372 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1373 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1374 | goto no_delegation_unlock; |
| 1375 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1376 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1377 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1378 | ret = 1; |
| 1379 | no_delegation_unlock: |
| 1380 | spin_unlock(&deleg_cur->lock); |
| 1381 | no_delegation: |
| 1382 | rcu_read_unlock(); |
| 1383 | |
| 1384 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1385 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1386 | ret = 1; |
| 1387 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1388 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1389 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1390 | |
| 1391 | return ret; |
| 1392 | } |
| 1393 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1394 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1395 | const nfs4_stateid *stateid) |
| 1396 | { |
| 1397 | struct nfs4_state *state = lsp->ls_state; |
| 1398 | bool ret = false; |
| 1399 | |
| 1400 | spin_lock(&state->state_lock); |
| 1401 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1402 | goto out_noupdate; |
| 1403 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1404 | goto out_noupdate; |
| 1405 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1406 | ret = true; |
| 1407 | out_noupdate: |
| 1408 | spin_unlock(&state->state_lock); |
| 1409 | return ret; |
| 1410 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1411 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1412 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1413 | { |
| 1414 | struct nfs_delegation *delegation; |
| 1415 | |
| 1416 | rcu_read_lock(); |
| 1417 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1418 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1419 | rcu_read_unlock(); |
| 1420 | return; |
| 1421 | } |
| 1422 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1423 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1424 | } |
| 1425 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1426 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1427 | { |
| 1428 | struct nfs4_state *state = opendata->state; |
| 1429 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1430 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1431 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1432 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1433 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1434 | nfs4_stateid stateid; |
| 1435 | int ret = -EAGAIN; |
| 1436 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1437 | for (;;) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1438 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1439 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1440 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1441 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1442 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1443 | } |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1444 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1445 | rcu_read_lock(); |
| 1446 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1447 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1448 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1449 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1450 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1451 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1452 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1453 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1454 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1455 | if (!opendata->is_recover) { |
| 1456 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1457 | if (ret != 0) |
| 1458 | goto out; |
| 1459 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1460 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1461 | |
| 1462 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1463 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1464 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1465 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1466 | out: |
| 1467 | return ERR_PTR(ret); |
| 1468 | out_return_state: |
| 1469 | atomic_inc(&state->count); |
| 1470 | return state; |
| 1471 | } |
| 1472 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1473 | static void |
| 1474 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1475 | { |
| 1476 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1477 | struct nfs_delegation *delegation; |
| 1478 | int delegation_flags = 0; |
| 1479 | |
| 1480 | rcu_read_lock(); |
| 1481 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1482 | if (delegation) |
| 1483 | delegation_flags = delegation->flags; |
| 1484 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1485 | switch (data->o_arg.claim) { |
| 1486 | default: |
| 1487 | break; |
| 1488 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1489 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1490 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1491 | "returning a delegation for " |
| 1492 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1493 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1494 | return; |
| 1495 | } |
| 1496 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1497 | nfs_inode_set_delegation(state->inode, |
| 1498 | data->owner->so_cred, |
| 1499 | &data->o_res); |
| 1500 | else |
| 1501 | nfs_inode_reclaim_delegation(state->inode, |
| 1502 | data->owner->so_cred, |
| 1503 | &data->o_res); |
| 1504 | } |
| 1505 | |
| 1506 | /* |
| 1507 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1508 | * and update the nfs4_state. |
| 1509 | */ |
| 1510 | static struct nfs4_state * |
| 1511 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1512 | { |
| 1513 | struct inode *inode = data->state->inode; |
| 1514 | struct nfs4_state *state = data->state; |
| 1515 | int ret; |
| 1516 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1517 | if (!data->rpc_done) { |
| 1518 | if (data->rpc_status) { |
| 1519 | ret = data->rpc_status; |
| 1520 | goto err; |
| 1521 | } |
| 1522 | /* cached opens have already been processed */ |
| 1523 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1526 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1527 | if (ret) |
| 1528 | goto err; |
| 1529 | |
| 1530 | if (data->o_res.delegation_type != 0) |
| 1531 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1532 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1533 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1534 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1535 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1536 | |
| 1537 | return state; |
| 1538 | err: |
| 1539 | return ERR_PTR(ret); |
| 1540 | |
| 1541 | } |
| 1542 | |
| 1543 | static struct nfs4_state * |
| 1544 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | { |
| 1546 | struct inode *inode; |
| 1547 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1548 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1550 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1551 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1552 | goto out; |
| 1553 | } |
| 1554 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1555 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1556 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1557 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1558 | 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] | 1559 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1560 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1561 | goto err; |
| 1562 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1563 | state = nfs4_get_open_state(inode, data->owner); |
| 1564 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1565 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1566 | if (data->o_res.delegation_type != 0) |
| 1567 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1568 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1569 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1570 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1571 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1572 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1573 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1574 | err_put_inode: |
| 1575 | iput(inode); |
| 1576 | err: |
| 1577 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1580 | static struct nfs4_state * |
| 1581 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1582 | { |
| 1583 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1584 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1585 | return _nfs4_opendata_to_nfs4_state(data); |
| 1586 | } |
| 1587 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1588 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1589 | { |
| 1590 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1591 | struct nfs_open_context *ctx; |
| 1592 | |
| 1593 | spin_lock(&state->inode->i_lock); |
| 1594 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1595 | if (ctx->state != state) |
| 1596 | continue; |
| 1597 | get_nfs_open_context(ctx); |
| 1598 | spin_unlock(&state->inode->i_lock); |
| 1599 | return ctx; |
| 1600 | } |
| 1601 | spin_unlock(&state->inode->i_lock); |
| 1602 | return ERR_PTR(-ENOENT); |
| 1603 | } |
| 1604 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1605 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1606 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1607 | { |
| 1608 | struct nfs4_opendata *opendata; |
| 1609 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1610 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1611 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1612 | if (opendata == NULL) |
| 1613 | return ERR_PTR(-ENOMEM); |
| 1614 | opendata->state = state; |
| 1615 | atomic_inc(&state->count); |
| 1616 | return opendata; |
| 1617 | } |
| 1618 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1619 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1620 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1621 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1622 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1623 | int ret; |
| 1624 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1625 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1626 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1627 | opendata->o_arg.open_flags = 0; |
| 1628 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1629 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1630 | NFS_SB(opendata->dentry->d_sb), |
| 1631 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1632 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1633 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1634 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1635 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1636 | if (ret != 0) |
| 1637 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1638 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1639 | if (IS_ERR(newstate)) |
| 1640 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1641 | if (newstate != opendata->state) |
| 1642 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1643 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1644 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1648 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1649 | int ret; |
| 1650 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1651 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1652 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1653 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1654 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1655 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1656 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1657 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1658 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1659 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1660 | if (ret != 0) |
| 1661 | return ret; |
| 1662 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1663 | if (ret != 0) |
| 1664 | return ret; |
| 1665 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1666 | if (ret != 0) |
| 1667 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1668 | /* |
| 1669 | * We may have performed cached opens for all three recoveries. |
| 1670 | * Check if we need to update the current stateid. |
| 1671 | */ |
| 1672 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1673 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1674 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1675 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1676 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1677 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1678 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1679 | return 0; |
| 1680 | } |
| 1681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | /* |
| 1683 | * OPEN_RECLAIM: |
| 1684 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1686 | 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] | 1687 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1688 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1689 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1690 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | int status; |
| 1692 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1693 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1694 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1695 | if (IS_ERR(opendata)) |
| 1696 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1697 | rcu_read_lock(); |
| 1698 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1699 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1700 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1701 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1702 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1703 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1704 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | return status; |
| 1706 | } |
| 1707 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1708 | 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] | 1709 | { |
| 1710 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1711 | struct nfs4_exception exception = { }; |
| 1712 | int err; |
| 1713 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1714 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1715 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1716 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1717 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1718 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1719 | break; |
| 1720 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } while (exception.retry); |
| 1722 | return err; |
| 1723 | } |
| 1724 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1725 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1726 | { |
| 1727 | struct nfs_open_context *ctx; |
| 1728 | int ret; |
| 1729 | |
| 1730 | ctx = nfs4_state_find_open_context(state); |
| 1731 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1732 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1733 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1734 | put_nfs_open_context(ctx); |
| 1735 | return ret; |
| 1736 | } |
| 1737 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1738 | 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] | 1739 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1740 | switch (err) { |
| 1741 | default: |
| 1742 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1743 | "%d.\n", __func__, err); |
| 1744 | case 0: |
| 1745 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1746 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1747 | case -ESTALE: |
| 1748 | break; |
| 1749 | case -NFS4ERR_BADSESSION: |
| 1750 | case -NFS4ERR_BADSLOT: |
| 1751 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1752 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1753 | case -NFS4ERR_DEADSESSION: |
| 1754 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1755 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1756 | return -EAGAIN; |
| 1757 | case -NFS4ERR_STALE_CLIENTID: |
| 1758 | case -NFS4ERR_STALE_STATEID: |
| 1759 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1760 | case -NFS4ERR_EXPIRED: |
| 1761 | /* Don't recall a delegation if it was lost */ |
| 1762 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1763 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1764 | case -NFS4ERR_MOVED: |
| 1765 | nfs4_schedule_migration_recovery(server); |
| 1766 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1767 | case -NFS4ERR_LEASE_MOVED: |
| 1768 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1769 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1770 | case -NFS4ERR_DELEG_REVOKED: |
| 1771 | case -NFS4ERR_ADMIN_REVOKED: |
| 1772 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1773 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1774 | nfs_inode_find_state_and_recover(state->inode, |
| 1775 | stateid); |
| 1776 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1777 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1778 | case -NFS4ERR_DELAY: |
| 1779 | case -NFS4ERR_GRACE: |
| 1780 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1781 | ssleep(1); |
| 1782 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1783 | case -ENOMEM: |
| 1784 | case -NFS4ERR_DENIED: |
| 1785 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1786 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | return err; |
| 1789 | } |
| 1790 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1791 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1792 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1793 | fmode_t type) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1794 | { |
| 1795 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1796 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1797 | int err = 0; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1798 | |
| 1799 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1800 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1801 | if (IS_ERR(opendata)) |
| 1802 | return PTR_ERR(opendata); |
| 1803 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1804 | write_seqlock(&state->seqlock); |
| 1805 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1806 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1807 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1808 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1809 | case FMODE_READ|FMODE_WRITE: |
| 1810 | case FMODE_WRITE: |
| 1811 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1812 | if (err) |
| 1813 | break; |
| 1814 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1815 | if (err) |
| 1816 | break; |
| 1817 | case FMODE_READ: |
| 1818 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1819 | } |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1820 | nfs4_opendata_put(opendata); |
| 1821 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1822 | } |
| 1823 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1824 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1825 | { |
| 1826 | struct nfs4_opendata *data = calldata; |
| 1827 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1828 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1829 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1830 | } |
| 1831 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1832 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1833 | { |
| 1834 | struct nfs4_opendata *data = calldata; |
| 1835 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1836 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1837 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1838 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1839 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1840 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1841 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1842 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1843 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1844 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | static void nfs4_open_confirm_release(void *calldata) |
| 1848 | { |
| 1849 | struct nfs4_opendata *data = calldata; |
| 1850 | struct nfs4_state *state = NULL; |
| 1851 | |
| 1852 | /* If this request hasn't been cancelled, do nothing */ |
| 1853 | if (data->cancelled == 0) |
| 1854 | goto out_free; |
| 1855 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1856 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1857 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1858 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1859 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1860 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1861 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1862 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1866 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1867 | .rpc_call_done = nfs4_open_confirm_done, |
| 1868 | .rpc_release = nfs4_open_confirm_release, |
| 1869 | }; |
| 1870 | |
| 1871 | /* |
| 1872 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1873 | */ |
| 1874 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1875 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1876 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1877 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1878 | struct rpc_message msg = { |
| 1879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1880 | .rpc_argp = &data->c_arg, |
| 1881 | .rpc_resp = &data->c_res, |
| 1882 | .rpc_cred = data->owner->so_cred, |
| 1883 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1884 | struct rpc_task_setup task_setup_data = { |
| 1885 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1886 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1887 | .callback_ops = &nfs4_open_confirm_ops, |
| 1888 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1889 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1890 | .flags = RPC_TASK_ASYNC, |
| 1891 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | int status; |
| 1893 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1894 | 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] | 1895 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1896 | data->rpc_done = 0; |
| 1897 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1898 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 1899 | if (data->is_recover) |
| 1900 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1901 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1902 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1903 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1904 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1905 | if (status != 0) { |
| 1906 | data->cancelled = 1; |
| 1907 | smp_wmb(); |
| 1908 | } else |
| 1909 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1910 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | return status; |
| 1912 | } |
| 1913 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1914 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1916 | struct nfs4_opendata *data = calldata; |
| 1917 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1918 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1919 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1920 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1921 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1922 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1923 | /* |
| 1924 | * Check if we still need to send an OPEN call, or if we can use |
| 1925 | * a delegation instead. |
| 1926 | */ |
| 1927 | if (data->state != NULL) { |
| 1928 | struct nfs_delegation *delegation; |
| 1929 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1930 | 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] | 1931 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1932 | rcu_read_lock(); |
| 1933 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1934 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1935 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1936 | rcu_read_unlock(); |
| 1937 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1938 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1939 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1940 | switch (claim) { |
| 1941 | default: |
| 1942 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1943 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1944 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1945 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1946 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1947 | case NFS4_OPEN_CLAIM_FH: |
| 1948 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1949 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1950 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1951 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1952 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1953 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1954 | &data->o_res.seq_res, |
| 1955 | task) != 0) |
| 1956 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1957 | |
| 1958 | /* Set the create mode (note dependency on the session type) */ |
| 1959 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1960 | if (data->o_arg.open_flags & O_EXCL) { |
| 1961 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1962 | if (nfs4_has_persistent_session(clp)) |
| 1963 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1964 | else if (clp->cl_mvops->minor_version > 0) |
| 1965 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1966 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1967 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1968 | unlock_no_action: |
| 1969 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1970 | out_no_action: |
| 1971 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1972 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1973 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1974 | } |
| 1975 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1976 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1977 | { |
| 1978 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1980 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1981 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1982 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1983 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1984 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1985 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1986 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1987 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1988 | case S_IFREG: |
| 1989 | break; |
| 1990 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1991 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1992 | break; |
| 1993 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1994 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1995 | break; |
| 1996 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1997 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1998 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1999 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2000 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2001 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2002 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2003 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2004 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2005 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2006 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2007 | static void nfs4_open_release(void *calldata) |
| 2008 | { |
| 2009 | struct nfs4_opendata *data = calldata; |
| 2010 | struct nfs4_state *state = NULL; |
| 2011 | |
| 2012 | /* If this request hasn't been cancelled, do nothing */ |
| 2013 | if (data->cancelled == 0) |
| 2014 | goto out_free; |
| 2015 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2016 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2017 | goto out_free; |
| 2018 | /* In case we need an open_confirm, no cleanup! */ |
| 2019 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2020 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2021 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2022 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2023 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2024 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2025 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2029 | .rpc_call_prepare = nfs4_open_prepare, |
| 2030 | .rpc_call_done = nfs4_open_done, |
| 2031 | .rpc_release = nfs4_open_release, |
| 2032 | }; |
| 2033 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2034 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2035 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2036 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2037 | struct nfs_server *server = NFS_SERVER(dir); |
| 2038 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2039 | struct nfs_openres *o_res = &data->o_res; |
| 2040 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2041 | struct rpc_message msg = { |
| 2042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2043 | .rpc_argp = o_arg, |
| 2044 | .rpc_resp = o_res, |
| 2045 | .rpc_cred = data->owner->so_cred, |
| 2046 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2047 | struct rpc_task_setup task_setup_data = { |
| 2048 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2049 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2050 | .callback_ops = &nfs4_open_ops, |
| 2051 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2052 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2053 | .flags = RPC_TASK_ASYNC, |
| 2054 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2055 | int status; |
| 2056 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2057 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2058 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2059 | data->rpc_done = 0; |
| 2060 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2061 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2062 | data->is_recover = 0; |
| 2063 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2064 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2065 | data->is_recover = 1; |
| 2066 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2067 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2068 | if (IS_ERR(task)) |
| 2069 | return PTR_ERR(task); |
| 2070 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2071 | if (status != 0) { |
| 2072 | data->cancelled = 1; |
| 2073 | smp_wmb(); |
| 2074 | } else |
| 2075 | status = data->rpc_status; |
| 2076 | rpc_put_task(task); |
| 2077 | |
| 2078 | return status; |
| 2079 | } |
| 2080 | |
| 2081 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2082 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2083 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2084 | struct nfs_openres *o_res = &data->o_res; |
| 2085 | int status; |
| 2086 | |
| 2087 | status = nfs4_run_open_task(data, 1); |
| 2088 | if (status != 0 || !data->rpc_done) |
| 2089 | return status; |
| 2090 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2091 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2092 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2093 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2094 | status = _nfs4_proc_open_confirm(data); |
| 2095 | if (status != 0) |
| 2096 | return status; |
| 2097 | } |
| 2098 | |
| 2099 | return status; |
| 2100 | } |
| 2101 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2102 | /* |
| 2103 | * Additional permission checks in order to distinguish between an |
| 2104 | * open for read, and an open for execute. This works around the |
| 2105 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2106 | * the same. |
| 2107 | * Note that in the non-execute case, we want to turn off permission |
| 2108 | * checking if we just created a new file (POSIX open() semantics). |
| 2109 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2110 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2111 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2112 | struct nfs4_state *state, fmode_t fmode, |
| 2113 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2114 | { |
| 2115 | struct nfs_access_entry cache; |
| 2116 | u32 mask; |
| 2117 | |
| 2118 | /* access call failed or for some reason the server doesn't |
| 2119 | * support any access modes -- defer access call until later */ |
| 2120 | if (opendata->o_res.access_supported == 0) |
| 2121 | return 0; |
| 2122 | |
| 2123 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2124 | /* |
| 2125 | * Use openflags to check for exec, because fmode won't |
| 2126 | * always have FMODE_EXEC set when file open for exec. |
| 2127 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2128 | if (openflags & __FMODE_EXEC) { |
| 2129 | /* ONLY check for exec rights */ |
| 2130 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2131 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2132 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2133 | |
| 2134 | cache.cred = cred; |
| 2135 | cache.jiffies = jiffies; |
| 2136 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2137 | nfs_access_add_cache(state->inode, &cache); |
| 2138 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2139 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2140 | return 0; |
| 2141 | |
| 2142 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2143 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2144 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2145 | } |
| 2146 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2147 | /* |
| 2148 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2149 | */ |
| 2150 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2151 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2152 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2153 | struct nfs_server *server = NFS_SERVER(dir); |
| 2154 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2155 | struct nfs_openres *o_res = &data->o_res; |
| 2156 | int status; |
| 2157 | |
| 2158 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2159 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2161 | if (status != 0) { |
| 2162 | if (status == -NFS4ERR_BADNAME && |
| 2163 | !(o_arg->open_flags & O_CREAT)) |
| 2164 | return -ENOENT; |
| 2165 | return status; |
| 2166 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2167 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2168 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2169 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2170 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2171 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2172 | if (o_arg->open_flags & O_EXCL) |
| 2173 | data->file_created = 1; |
| 2174 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2175 | data->file_created = 1; |
| 2176 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2177 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2178 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2180 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2182 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | } |
| 2184 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2185 | 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] | 2186 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2189 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2190 | { |
| 2191 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2192 | } |
| 2193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | /* |
| 2195 | * OPEN_EXPIRED: |
| 2196 | * reclaim state on the server after a network partition. |
| 2197 | * Assumes caller holds the appropriate lock |
| 2198 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2199 | 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] | 2200 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2201 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2202 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2204 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2205 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2206 | if (IS_ERR(opendata)) |
| 2207 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2208 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2209 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2210 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2211 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2212 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2215 | 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] | 2216 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2217 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2218 | struct nfs4_exception exception = { }; |
| 2219 | int err; |
| 2220 | |
| 2221 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2222 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2223 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2224 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2225 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2226 | switch (err) { |
| 2227 | default: |
| 2228 | goto out; |
| 2229 | case -NFS4ERR_GRACE: |
| 2230 | case -NFS4ERR_DELAY: |
| 2231 | nfs4_handle_exception(server, err, &exception); |
| 2232 | err = 0; |
| 2233 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2234 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2235 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2236 | return err; |
| 2237 | } |
| 2238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2240 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2242 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2244 | ctx = nfs4_state_find_open_context(state); |
| 2245 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2246 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2247 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2248 | put_nfs_open_context(ctx); |
| 2249 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2252 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2253 | { |
| 2254 | nfs_remove_bad_delegation(state->inode); |
| 2255 | write_seqlock(&state->seqlock); |
| 2256 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2257 | write_sequnlock(&state->seqlock); |
| 2258 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2259 | } |
| 2260 | |
| 2261 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2262 | { |
| 2263 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2264 | nfs_finish_clear_delegation_stateid(state); |
| 2265 | } |
| 2266 | |
| 2267 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2268 | { |
| 2269 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2270 | nfs40_clear_delegation_stateid(state); |
| 2271 | return nfs4_open_expired(sp, state); |
| 2272 | } |
| 2273 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2274 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2275 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2276 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2277 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2278 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2279 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2280 | struct rpc_cred *cred; |
| 2281 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2282 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2283 | /* Get the delegation credential for use by test/free_stateid */ |
| 2284 | rcu_read_lock(); |
| 2285 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2286 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2287 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2288 | return; |
| 2289 | } |
| 2290 | |
| 2291 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2292 | cred = get_rpccred(delegation->cred); |
| 2293 | rcu_read_unlock(); |
| 2294 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2295 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2296 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2297 | if (status != NFS_OK) { |
| 2298 | /* Free the stateid unless the server explicitly |
| 2299 | * informs us the stateid is unrecognized. */ |
| 2300 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2301 | nfs41_free_stateid(server, &stateid, cred); |
| 2302 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2303 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2304 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2305 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2310 | * |
| 2311 | * @state: NFSv4 state for an inode |
| 2312 | * |
| 2313 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2314 | * Otherwise a negative NFS4ERR value is returned. |
| 2315 | */ |
| 2316 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2317 | { |
| 2318 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2319 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2320 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2321 | int status; |
| 2322 | |
| 2323 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2324 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2325 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2326 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2327 | return -NFS4ERR_BAD_STATEID; |
| 2328 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2329 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2330 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2331 | if (status != NFS_OK) { |
| 2332 | /* Free the stateid unless the server explicitly |
| 2333 | * informs us the stateid is unrecognized. */ |
| 2334 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2335 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2336 | |
| 2337 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2338 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2339 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2340 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2341 | } |
| 2342 | return status; |
| 2343 | } |
| 2344 | |
| 2345 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2346 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2347 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2348 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2349 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2350 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2351 | if (status != NFS_OK) |
| 2352 | status = nfs4_open_expired(sp, state); |
| 2353 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2354 | } |
| 2355 | #endif |
| 2356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2358 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2359 | * fields corresponding to attributes that were used to store the verifier. |
| 2360 | * Make sure we clobber those fields in the later setattr call |
| 2361 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2362 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2363 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2364 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2365 | const u32 *attrset = opendata->o_res.attrset; |
| 2366 | |
| 2367 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2368 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2369 | sattr->ia_valid |= ATTR_ATIME; |
| 2370 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2371 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2372 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2373 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2374 | |
| 2375 | /* Except MODE, it seems harmless of setting twice. */ |
| 2376 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2377 | sattr->ia_valid &= ~ATTR_MODE; |
| 2378 | |
| 2379 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2380 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2381 | } |
| 2382 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2383 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2384 | fmode_t fmode, |
| 2385 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2386 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2387 | { |
| 2388 | struct nfs4_state_owner *sp = opendata->owner; |
| 2389 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2390 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2391 | struct nfs4_state *state; |
| 2392 | unsigned int seq; |
| 2393 | int ret; |
| 2394 | |
| 2395 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2396 | |
| 2397 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2398 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2399 | goto out; |
| 2400 | |
| 2401 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2402 | ret = PTR_ERR(state); |
| 2403 | if (IS_ERR(state)) |
| 2404 | goto out; |
| 2405 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2406 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2407 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2408 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2409 | if (d_really_is_negative(dentry)) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2410 | /* FIXME: Is this d_drop() ever needed? */ |
| 2411 | d_drop(dentry); |
| 2412 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2413 | if (dentry == NULL) { |
| 2414 | dentry = opendata->dentry; |
| 2415 | } else if (dentry != ctx->dentry) { |
| 2416 | dput(ctx->dentry); |
| 2417 | ctx->dentry = dget(dentry); |
| 2418 | } |
| 2419 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2420 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2423 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2424 | if (ret != 0) |
| 2425 | goto out; |
| 2426 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2427 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2428 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2429 | nfs_inode_attach_open_context(ctx); |
| 2430 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2431 | nfs4_schedule_stateid_recovery(server, state); |
| 2432 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2433 | out: |
| 2434 | return ret; |
| 2435 | } |
| 2436 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2437 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2438 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2440 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2441 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2442 | int flags, |
| 2443 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2444 | struct nfs4_label *label, |
| 2445 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | { |
| 2447 | struct nfs4_state_owner *sp; |
| 2448 | struct nfs4_state *state = NULL; |
| 2449 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2450 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2451 | struct dentry *dentry = ctx->dentry; |
| 2452 | struct rpc_cred *cred = ctx->cred; |
| 2453 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2454 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2455 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2456 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2457 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
| 2459 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2461 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2462 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2464 | goto out_err; |
| 2465 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2466 | status = nfs4_recover_expired_lease(server); |
| 2467 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2468 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2469 | if (d_really_is_positive(dentry)) |
| 2470 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2471 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2472 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2473 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2474 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2475 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2476 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2477 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2479 | if (label) { |
| 2480 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2481 | if (IS_ERR(olabel)) { |
| 2482 | status = PTR_ERR(olabel); |
| 2483 | goto err_opendata_put; |
| 2484 | } |
| 2485 | } |
| 2486 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2487 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2488 | if (!opendata->f_attr.mdsthreshold) { |
| 2489 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2490 | if (!opendata->f_attr.mdsthreshold) |
| 2491 | goto err_free_label; |
| 2492 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2493 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2494 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2495 | if (d_really_is_positive(dentry)) |
| 2496 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2497 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2498 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2499 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2500 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2501 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2502 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2503 | 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] | 2504 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2505 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2506 | |
| 2507 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2508 | status = nfs4_do_setattr(state->inode, cred, |
| 2509 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2510 | state, label, olabel); |
| 2511 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 2512 | nfs_setattr_update_inode(state->inode, sattr, |
| 2513 | opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2514 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2515 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2516 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2517 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2518 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2519 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2520 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2521 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2522 | opendata->f_attr.mdsthreshold = NULL; |
| 2523 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2524 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2525 | nfs4_label_free(olabel); |
| 2526 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2527 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2530 | err_free_label: |
| 2531 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2532 | err_opendata_put: |
| 2533 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2534 | err_put_state_owner: |
| 2535 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | return status; |
| 2538 | } |
| 2539 | |
| 2540 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2541 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2542 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2543 | int flags, |
| 2544 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2545 | struct nfs4_label *label, |
| 2546 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2548 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | struct nfs4_exception exception = { }; |
| 2550 | struct nfs4_state *res; |
| 2551 | int status; |
| 2552 | |
| 2553 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2554 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2555 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2556 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | if (status == 0) |
| 2558 | break; |
| 2559 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2560 | * book-keeping w.r.t. state-changing operations |
| 2561 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2562 | * It is actually a sign of a bug on the client or on the server. |
| 2563 | * |
| 2564 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2565 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | * have unhashed the old state_owner for us, and that we can |
| 2567 | * therefore safely retry using a new one. We should still warn |
| 2568 | * the user though... |
| 2569 | */ |
| 2570 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2571 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2572 | " returned a bad sequence-id error!\n", |
| 2573 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | exception.retry = 1; |
| 2575 | continue; |
| 2576 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2577 | /* |
| 2578 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2579 | * state before it received the OPEN_CONFIRM. |
| 2580 | * Recover by retrying the request as per the discussion |
| 2581 | * on Page 181 of RFC3530. |
| 2582 | */ |
| 2583 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2584 | exception.retry = 1; |
| 2585 | continue; |
| 2586 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2587 | if (status == -EAGAIN) { |
| 2588 | /* We must have found a delegation */ |
| 2589 | exception.retry = 1; |
| 2590 | continue; |
| 2591 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2592 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2593 | continue; |
| 2594 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | status, &exception)); |
| 2596 | } while (exception.retry); |
| 2597 | return res; |
| 2598 | } |
| 2599 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2600 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2601 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2602 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2603 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2605 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2607 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | .iap = sattr, |
| 2609 | .server = server, |
| 2610 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2611 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | }; |
| 2613 | struct nfs_setattrres res = { |
| 2614 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2615 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | .server = server, |
| 2617 | }; |
| 2618 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2620 | .rpc_argp = &arg, |
| 2621 | .rpc_resp = &res, |
| 2622 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2624 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2625 | fmode_t fmode; |
| 2626 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2627 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2629 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2630 | if (ilabel) |
| 2631 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2632 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2633 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2635 | /* Servers should only apply open mode checks for file size changes */ |
| 2636 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2637 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2638 | |
| 2639 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2640 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2641 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2642 | struct nfs_lockowner lockowner = { |
| 2643 | .l_owner = current->files, |
| 2644 | .l_pid = current->tgid, |
| 2645 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2646 | if (!nfs4_valid_open_stateid(state)) |
| 2647 | return -EBADF; |
| 2648 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2649 | &lockowner) == -EIO) |
| 2650 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2651 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2652 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2654 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2655 | if (status == 0 && state != NULL) |
| 2656 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2657 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2660 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2661 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2662 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2663 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2665 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2666 | struct nfs4_exception exception = { |
| 2667 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2668 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2669 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | int err; |
| 2671 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2672 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2673 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2674 | switch (err) { |
| 2675 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2676 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2677 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2678 | "applying open mode checks to " |
| 2679 | "a SETATTR that is not " |
| 2680 | "changing file size.\n", |
| 2681 | server->nfs_client->cl_hostname); |
| 2682 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2683 | if (state && !(state->state & FMODE_WRITE)) { |
| 2684 | err = -EBADF; |
| 2685 | if (sattr->ia_valid & ATTR_OPEN) |
| 2686 | err = -EACCES; |
| 2687 | goto out; |
| 2688 | } |
| 2689 | } |
| 2690 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2692 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | return err; |
| 2694 | } |
| 2695 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2696 | static bool |
| 2697 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2698 | { |
| 2699 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2700 | return false; |
| 2701 | |
| 2702 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2703 | } |
| 2704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | struct nfs4_closedata { |
| 2706 | struct inode *inode; |
| 2707 | struct nfs4_state *state; |
| 2708 | struct nfs_closeargs arg; |
| 2709 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2710 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2711 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2712 | bool roc; |
| 2713 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | }; |
| 2715 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2716 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2717 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2718 | struct nfs4_closedata *calldata = data; |
| 2719 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2720 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2721 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2722 | if (calldata->roc) |
| 2723 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2724 | nfs4_put_open_state(calldata->state); |
| 2725 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2726 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2727 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2728 | kfree(calldata); |
| 2729 | } |
| 2730 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2731 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2733 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2736 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2738 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2739 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2740 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2741 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | /* hmm. we are done with the inode, and in the process of freeing |
| 2743 | * the state_owner. we keep this around to process errors |
| 2744 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | switch (task->tk_status) { |
| 2746 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2747 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2748 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2749 | pnfs_roc_set_barrier(state->inode, |
| 2750 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2751 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2752 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2753 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2755 | case -NFS4ERR_OLD_STATEID: |
| 2756 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2758 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2759 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2760 | rpc_restart_call_prepare(task); |
| 2761 | goto out_release; |
| 2762 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2763 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2764 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2766 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2767 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2768 | goto out_release; |
| 2769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2771 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2772 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2773 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2774 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2775 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2776 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2779 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2781 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2782 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2783 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2784 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2785 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2786 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2787 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2788 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2789 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2790 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2791 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2792 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2793 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2794 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2795 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2796 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2797 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2798 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2799 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2800 | if (state->n_rdonly == 0) |
| 2801 | call_close |= is_rdonly; |
| 2802 | else if (is_rdonly) |
| 2803 | calldata->arg.fmode |= FMODE_READ; |
| 2804 | if (state->n_wronly == 0) |
| 2805 | call_close |= is_wronly; |
| 2806 | else if (is_wronly) |
| 2807 | calldata->arg.fmode |= FMODE_WRITE; |
| 2808 | } else if (is_rdwr) |
| 2809 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2810 | |
| 2811 | if (calldata->arg.fmode == 0) |
| 2812 | call_close |= is_rdwr; |
| 2813 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2814 | if (!nfs4_valid_open_stateid(state)) |
| 2815 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2816 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2817 | |
| 2818 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2819 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2820 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2821 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2822 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2823 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2824 | nfs_release_seqid(calldata->arg.seqid); |
| 2825 | goto out_wait; |
| 2826 | } |
| 2827 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2828 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2829 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2830 | if (calldata->roc) |
| 2831 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2832 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2833 | calldata->arg.share_access = |
| 2834 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2835 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2836 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2837 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2838 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2839 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2840 | &calldata->arg.seq_args, |
| 2841 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2842 | task) != 0) |
| 2843 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2844 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2845 | return; |
| 2846 | out_no_action: |
| 2847 | task->tk_action = NULL; |
| 2848 | out_wait: |
| 2849 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2852 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2853 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2854 | .rpc_call_done = nfs4_close_done, |
| 2855 | .rpc_release = nfs4_free_closedata, |
| 2856 | }; |
| 2857 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2858 | static bool nfs4_roc(struct inode *inode) |
| 2859 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 2860 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2861 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2862 | return pnfs_roc(inode); |
| 2863 | } |
| 2864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | /* |
| 2866 | * It is possible for data to be read/written from a mem-mapped file |
| 2867 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2868 | * This means that we can't safely call nfsv4 close on a file until |
| 2869 | * the inode is cleared. This in turn means that we are not good |
| 2870 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2871 | * share state even when we are done with one of the three share |
| 2872 | * stateid's in the inode. |
| 2873 | * |
| 2874 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2875 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2876 | 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] | 2877 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2878 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2879 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2881 | struct nfs4_state_owner *sp = state->owner; |
| 2882 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2883 | struct rpc_message msg = { |
| 2884 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2885 | .rpc_cred = state->owner->so_cred, |
| 2886 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2887 | struct rpc_task_setup task_setup_data = { |
| 2888 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2889 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2890 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2891 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2892 | .flags = RPC_TASK_ASYNC, |
| 2893 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2894 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2896 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2897 | &task_setup_data.rpc_client, &msg); |
| 2898 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2899 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2901 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2902 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2903 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2905 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2907 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 2908 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 2909 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2910 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2911 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2912 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2913 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2914 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2915 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2916 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2917 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2918 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2919 | msg.rpc_argp = &calldata->arg; |
| 2920 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2921 | task_setup_data.callback_data = calldata; |
| 2922 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2923 | if (IS_ERR(task)) |
| 2924 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2925 | status = 0; |
| 2926 | if (wait) |
| 2927 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2928 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2929 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2930 | out_free_calldata: |
| 2931 | kfree(calldata); |
| 2932 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2933 | nfs4_put_open_state(state); |
| 2934 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2935 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2938 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2939 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2940 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2943 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2944 | |
| 2945 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2947 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2948 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2949 | |
| 2950 | nfs4_label_release_security(label); |
| 2951 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2952 | if (IS_ERR(state)) |
| 2953 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2954 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2957 | 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] | 2958 | { |
| 2959 | if (ctx->state == NULL) |
| 2960 | return; |
| 2961 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2962 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2963 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2964 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2967 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2968 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2969 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2972 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 2973 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2974 | struct nfs4_server_caps_arg args = { |
| 2975 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 2976 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2977 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | struct nfs4_server_caps_res res = {}; |
| 2979 | struct rpc_message msg = { |
| 2980 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2981 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | .rpc_resp = &res, |
| 2983 | }; |
| 2984 | int status; |
| 2985 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 2986 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 2987 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 2988 | FATTR4_WORD0_LINK_SUPPORT | |
| 2989 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 2990 | FATTR4_WORD0_ACLSUPPORT; |
| 2991 | if (minorversion) |
| 2992 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 2993 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2994 | 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] | 2995 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2996 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 2997 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2998 | case 0: |
| 2999 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3000 | res.attr_bitmask[2] = 0; |
| 3001 | break; |
| 3002 | case 1: |
| 3003 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3004 | break; |
| 3005 | case 2: |
| 3006 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3007 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3009 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3010 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3011 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3012 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3013 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3014 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3015 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3016 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | server->caps |= NFS_CAP_ACLS; |
| 3018 | if (res.has_links != 0) |
| 3019 | server->caps |= NFS_CAP_HARDLINKS; |
| 3020 | if (res.has_symlinks != 0) |
| 3021 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3022 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3023 | server->caps |= NFS_CAP_FILEID; |
| 3024 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3025 | server->caps |= NFS_CAP_MODE; |
| 3026 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3027 | server->caps |= NFS_CAP_NLINK; |
| 3028 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3029 | server->caps |= NFS_CAP_OWNER; |
| 3030 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3031 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3032 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3033 | server->caps |= NFS_CAP_ATIME; |
| 3034 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3035 | server->caps |= NFS_CAP_CTIME; |
| 3036 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3037 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3038 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3039 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3040 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3041 | #endif |
| 3042 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3043 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3044 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3045 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3046 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3047 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3048 | 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] | 3049 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3050 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3051 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3053 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | return status; |
| 3057 | } |
| 3058 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3059 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | { |
| 3061 | struct nfs4_exception exception = { }; |
| 3062 | int err; |
| 3063 | do { |
| 3064 | err = nfs4_handle_exception(server, |
| 3065 | _nfs4_server_capabilities(server, fhandle), |
| 3066 | &exception); |
| 3067 | } while (exception.retry); |
| 3068 | return err; |
| 3069 | } |
| 3070 | |
| 3071 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3072 | struct nfs_fsinfo *info) |
| 3073 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3074 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3076 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | }; |
| 3078 | struct nfs4_lookup_res res = { |
| 3079 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3080 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | .fh = fhandle, |
| 3082 | }; |
| 3083 | struct rpc_message msg = { |
| 3084 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3085 | .rpc_argp = &args, |
| 3086 | .rpc_resp = &res, |
| 3087 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3088 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3089 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3090 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3091 | /* |
| 3092 | * Process the label in the upcoming getfattr |
| 3093 | */ |
| 3094 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3095 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3096 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3097 | 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] | 3098 | } |
| 3099 | |
| 3100 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3101 | struct nfs_fsinfo *info) |
| 3102 | { |
| 3103 | struct nfs4_exception exception = { }; |
| 3104 | int err; |
| 3105 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3106 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3107 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3108 | switch (err) { |
| 3109 | case 0: |
| 3110 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3111 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3112 | default: |
| 3113 | err = nfs4_handle_exception(server, err, &exception); |
| 3114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3116 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | return err; |
| 3118 | } |
| 3119 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3120 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3121 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3122 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3123 | struct rpc_auth_create_args auth_args = { |
| 3124 | .pseudoflavor = flavor, |
| 3125 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3126 | struct rpc_auth *auth; |
| 3127 | int ret; |
| 3128 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3129 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3130 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3131 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3132 | goto out; |
| 3133 | } |
| 3134 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3135 | out: |
| 3136 | return ret; |
| 3137 | } |
| 3138 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3139 | /* |
| 3140 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3141 | * |
| 3142 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3143 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3144 | * |
| 3145 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3146 | * negative errno value. |
| 3147 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3148 | 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] | 3149 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3151 | /* Per 3530bis 15.33.5 */ |
| 3152 | static const rpc_authflavor_t flav_array[] = { |
| 3153 | RPC_AUTH_GSS_KRB5P, |
| 3154 | RPC_AUTH_GSS_KRB5I, |
| 3155 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3156 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3157 | RPC_AUTH_NULL, |
| 3158 | }; |
| 3159 | int status = -EPERM; |
| 3160 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3162 | if (server->auth_info.flavor_len > 0) { |
| 3163 | /* try each flavor specified by user */ |
| 3164 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3165 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3166 | server->auth_info.flavors[i]); |
| 3167 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3168 | continue; |
| 3169 | break; |
| 3170 | } |
| 3171 | } else { |
| 3172 | /* no flavors specified by user, try default list */ |
| 3173 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3174 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3175 | flav_array[i]); |
| 3176 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3177 | continue; |
| 3178 | break; |
| 3179 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3180 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3181 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3182 | /* |
| 3183 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3184 | * to access the mount. It could also mean that we tried to mount |
| 3185 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3186 | * existing mount programs don't handle -EACCES very well so it should |
| 3187 | * be mapped to -EPERM instead. |
| 3188 | */ |
| 3189 | if (status == -EACCES) |
| 3190 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3191 | return status; |
| 3192 | } |
| 3193 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3194 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3195 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3196 | { |
| 3197 | int mv = server->nfs_client->cl_minorversion; |
| 3198 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3199 | } |
| 3200 | |
| 3201 | /** |
| 3202 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3203 | * @server: initialized nfs_server handle |
| 3204 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3205 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3206 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3207 | * |
| 3208 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3209 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3210 | 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] | 3211 | struct nfs_fsinfo *info, |
| 3212 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3213 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3214 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3215 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3216 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3217 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3218 | |
| 3219 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3220 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 3221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | if (status == 0) |
| 3223 | status = nfs4_server_capabilities(server, fhandle); |
| 3224 | if (status == 0) |
| 3225 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3226 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3227 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3230 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3231 | struct nfs_fsinfo *info) |
| 3232 | { |
| 3233 | int error; |
| 3234 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3235 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3236 | |
| 3237 | error = nfs4_server_capabilities(server, mntfh); |
| 3238 | if (error < 0) { |
| 3239 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3240 | return error; |
| 3241 | } |
| 3242 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3243 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3244 | if (IS_ERR(label)) |
| 3245 | return PTR_ERR(label); |
| 3246 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3247 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3248 | if (error < 0) { |
| 3249 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3250 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3254 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3255 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3256 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3257 | err_free_label: |
| 3258 | nfs4_label_free(label); |
| 3259 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3260 | return error; |
| 3261 | } |
| 3262 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3263 | /* |
| 3264 | * Get locations and (maybe) other attributes of a referral. |
| 3265 | * Note that we'll actually follow the referral later when |
| 3266 | * we detect fsid mismatch in inode revalidation |
| 3267 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3268 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3269 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3270 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3271 | { |
| 3272 | int status = -ENOMEM; |
| 3273 | struct page *page = NULL; |
| 3274 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3275 | |
| 3276 | page = alloc_page(GFP_KERNEL); |
| 3277 | if (page == NULL) |
| 3278 | goto out; |
| 3279 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3280 | if (locations == NULL) |
| 3281 | goto out; |
| 3282 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3283 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3284 | if (status != 0) |
| 3285 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3286 | |
| 3287 | /* |
| 3288 | * If the fsid didn't change, this is a migration event, not a |
| 3289 | * referral. Cause us to drop into the exception handler, which |
| 3290 | * will kick off migration recovery. |
| 3291 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3292 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3293 | dprintk("%s: server did not return a different fsid for" |
| 3294 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3295 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3296 | goto out; |
| 3297 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3298 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3299 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3300 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3301 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3302 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3303 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3304 | out: |
| 3305 | if (page) |
| 3306 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3307 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3308 | return status; |
| 3309 | } |
| 3310 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3311 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3312 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | { |
| 3314 | struct nfs4_getattr_arg args = { |
| 3315 | .fh = fhandle, |
| 3316 | .bitmask = server->attr_bitmask, |
| 3317 | }; |
| 3318 | struct nfs4_getattr_res res = { |
| 3319 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3320 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | .server = server, |
| 3322 | }; |
| 3323 | struct rpc_message msg = { |
| 3324 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3325 | .rpc_argp = &args, |
| 3326 | .rpc_resp = &res, |
| 3327 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3328 | |
| 3329 | args.bitmask = nfs4_bitmask(server, label); |
| 3330 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3331 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3332 | 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] | 3333 | } |
| 3334 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3335 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3336 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | { |
| 3338 | struct nfs4_exception exception = { }; |
| 3339 | int err; |
| 3340 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3341 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3342 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3343 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | &exception); |
| 3345 | } while (exception.retry); |
| 3346 | return err; |
| 3347 | } |
| 3348 | |
| 3349 | /* |
| 3350 | * The file is not closed if it is opened due to the a request to change |
| 3351 | * the size of the file. The open call will not be needed once the |
| 3352 | * VFS layer lookup-intents are implemented. |
| 3353 | * |
| 3354 | * Close is called when the inode is destroyed. |
| 3355 | * If we haven't opened the file for O_WRONLY, we |
| 3356 | * need to in the size_change case to obtain a stateid. |
| 3357 | * |
| 3358 | * Got race? |
| 3359 | * Because OPEN is always done by name in nfsv4, it is |
| 3360 | * possible that we opened a different file by the same |
| 3361 | * name. We can recognize this race condition, but we |
| 3362 | * can't do anything about it besides returning an error. |
| 3363 | * |
| 3364 | * This will be fixed with VFS changes (lookup-intent). |
| 3365 | */ |
| 3366 | static int |
| 3367 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3368 | struct iattr *sattr) |
| 3369 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3370 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3371 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3372 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3373 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | int status; |
| 3375 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3376 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3377 | sattr->ia_valid & ATTR_SIZE && |
| 3378 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3379 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3380 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3381 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3383 | /* Deal with open(O_TRUNC) */ |
| 3384 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3385 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3386 | |
| 3387 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3388 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3389 | return 0; |
| 3390 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3391 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3392 | if (sattr->ia_valid & ATTR_FILE) { |
| 3393 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3394 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3395 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3396 | if (ctx) { |
| 3397 | cred = ctx->cred; |
| 3398 | state = ctx->state; |
| 3399 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3400 | } |
| 3401 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3402 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3403 | if (IS_ERR(label)) |
| 3404 | return PTR_ERR(label); |
| 3405 | |
| 3406 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3407 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3408 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3409 | nfs_setsecurity(inode, fattr, label); |
| 3410 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3411 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | return status; |
| 3413 | } |
| 3414 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3415 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3416 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3417 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3418 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3419 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3420 | int status; |
| 3421 | struct nfs4_lookup_arg args = { |
| 3422 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3423 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3424 | .name = name, |
| 3425 | }; |
| 3426 | struct nfs4_lookup_res res = { |
| 3427 | .server = server, |
| 3428 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3429 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3430 | .fh = fhandle, |
| 3431 | }; |
| 3432 | struct rpc_message msg = { |
| 3433 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3434 | .rpc_argp = &args, |
| 3435 | .rpc_resp = &res, |
| 3436 | }; |
| 3437 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3438 | args.bitmask = nfs4_bitmask(server, label); |
| 3439 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3440 | nfs_fattr_init(fattr); |
| 3441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3443 | 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] | 3444 | dprintk("NFS reply lookup: %d\n", status); |
| 3445 | return status; |
| 3446 | } |
| 3447 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3448 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3449 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3450 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3451 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3452 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3453 | fattr->nlink = 2; |
| 3454 | } |
| 3455 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3456 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3457 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3458 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3459 | { |
| 3460 | struct nfs4_exception exception = { }; |
| 3461 | struct rpc_clnt *client = *clnt; |
| 3462 | int err; |
| 3463 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3464 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3465 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3466 | switch (err) { |
| 3467 | case -NFS4ERR_BADNAME: |
| 3468 | err = -ENOENT; |
| 3469 | goto out; |
| 3470 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3471 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3472 | if (err == -NFS4ERR_MOVED) |
| 3473 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3474 | goto out; |
| 3475 | case -NFS4ERR_WRONGSEC: |
| 3476 | err = -EPERM; |
| 3477 | if (client != *clnt) |
| 3478 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3479 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3480 | if (IS_ERR(client)) |
| 3481 | return PTR_ERR(client); |
| 3482 | |
| 3483 | exception.retry = 1; |
| 3484 | break; |
| 3485 | default: |
| 3486 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3487 | } |
| 3488 | } while (exception.retry); |
| 3489 | |
| 3490 | out: |
| 3491 | if (err == 0) |
| 3492 | *clnt = client; |
| 3493 | else if (client != *clnt) |
| 3494 | rpc_shutdown_client(client); |
| 3495 | |
| 3496 | return err; |
| 3497 | } |
| 3498 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3499 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3500 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3501 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3503 | int status; |
| 3504 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3505 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3506 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3507 | if (client != NFS_CLIENT(dir)) { |
| 3508 | rpc_shutdown_client(client); |
| 3509 | nfs_fixup_secinfo_attributes(fattr); |
| 3510 | } |
| 3511 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3514 | struct rpc_clnt * |
| 3515 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3516 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3517 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3518 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3519 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3520 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3521 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3522 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3523 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3524 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3525 | } |
| 3526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3528 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3529 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | struct nfs4_accessargs args = { |
| 3531 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3532 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3534 | struct nfs4_accessres res = { |
| 3535 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3536 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | struct rpc_message msg = { |
| 3538 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3539 | .rpc_argp = &args, |
| 3540 | .rpc_resp = &res, |
| 3541 | .rpc_cred = entry->cred, |
| 3542 | }; |
| 3543 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3544 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | |
| 3546 | /* |
| 3547 | * Determine which access bits we want to ask for... |
| 3548 | */ |
| 3549 | if (mode & MAY_READ) |
| 3550 | args.access |= NFS4_ACCESS_READ; |
| 3551 | if (S_ISDIR(inode->i_mode)) { |
| 3552 | if (mode & MAY_WRITE) |
| 3553 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3554 | if (mode & MAY_EXEC) |
| 3555 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3556 | } else { |
| 3557 | if (mode & MAY_WRITE) |
| 3558 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3559 | if (mode & MAY_EXEC) |
| 3560 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3561 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3562 | |
| 3563 | res.fattr = nfs_alloc_fattr(); |
| 3564 | if (res.fattr == NULL) |
| 3565 | return -ENOMEM; |
| 3566 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3567 | 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] | 3568 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3569 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3570 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3572 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | return status; |
| 3574 | } |
| 3575 | |
| 3576 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3577 | { |
| 3578 | struct nfs4_exception exception = { }; |
| 3579 | int err; |
| 3580 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3581 | err = _nfs4_proc_access(inode, entry); |
| 3582 | trace_nfs4_access(inode, err); |
| 3583 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | &exception); |
| 3585 | } while (exception.retry); |
| 3586 | return err; |
| 3587 | } |
| 3588 | |
| 3589 | /* |
| 3590 | * TODO: For the time being, we don't try to get any attributes |
| 3591 | * along with any of the zero-copy operations READ, READDIR, |
| 3592 | * READLINK, WRITE. |
| 3593 | * |
| 3594 | * In the case of the first three, we want to put the GETATTR |
| 3595 | * after the read-type operation -- this is because it is hard |
| 3596 | * to predict the length of a GETATTR response in v4, and thus |
| 3597 | * align the READ data correctly. This means that the GETATTR |
| 3598 | * may end up partially falling into the page cache, and we should |
| 3599 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3600 | * To do this efficiently, we need to know the total length |
| 3601 | * of data received, which doesn't seem to be available outside |
| 3602 | * of the RPC layer. |
| 3603 | * |
| 3604 | * In the case of WRITE, we also want to put the GETATTR after |
| 3605 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3606 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | * |
| 3608 | * Both of these changes to the XDR layer would in fact be quite |
| 3609 | * minor, but I decided to leave them for a subsequent patch. |
| 3610 | */ |
| 3611 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3612 | unsigned int pgbase, unsigned int pglen) |
| 3613 | { |
| 3614 | struct nfs4_readlink args = { |
| 3615 | .fh = NFS_FH(inode), |
| 3616 | .pgbase = pgbase, |
| 3617 | .pglen = pglen, |
| 3618 | .pages = &page, |
| 3619 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3620 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | struct rpc_message msg = { |
| 3622 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3623 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3624 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | }; |
| 3626 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3627 | 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] | 3628 | } |
| 3629 | |
| 3630 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3631 | unsigned int pgbase, unsigned int pglen) |
| 3632 | { |
| 3633 | struct nfs4_exception exception = { }; |
| 3634 | int err; |
| 3635 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3636 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3637 | trace_nfs4_readlink(inode, err); |
| 3638 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | &exception); |
| 3640 | } while (exception.retry); |
| 3641 | return err; |
| 3642 | } |
| 3643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3645 | * 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] | 3646 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | static int |
| 3648 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3649 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3651 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3652 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | int status = 0; |
| 3655 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3656 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3657 | if (IS_ERR(ctx)) |
| 3658 | return PTR_ERR(ctx); |
| 3659 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3660 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3661 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3662 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3663 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | if (IS_ERR(state)) { |
| 3665 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3666 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3669 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3670 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | return status; |
| 3672 | } |
| 3673 | |
| 3674 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3675 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3676 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3677 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3679 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3681 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3682 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3683 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3685 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3686 | .rpc_argp = &args, |
| 3687 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3689 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3690 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3691 | 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] | 3692 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3693 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | return status; |
| 3695 | } |
| 3696 | |
| 3697 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3698 | { |
| 3699 | struct nfs4_exception exception = { }; |
| 3700 | int err; |
| 3701 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3702 | err = _nfs4_proc_remove(dir, name); |
| 3703 | trace_nfs4_remove(dir, name, err); |
| 3704 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | &exception); |
| 3706 | } while (exception.retry); |
| 3707 | return err; |
| 3708 | } |
| 3709 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3710 | 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] | 3711 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3712 | struct nfs_server *server = NFS_SERVER(dir); |
| 3713 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3714 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3716 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3718 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3719 | |
| 3720 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3723 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3724 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3725 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3726 | &data->args.seq_args, |
| 3727 | &data->res.seq_res, |
| 3728 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3731 | 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] | 3732 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3733 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3734 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3735 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3736 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3737 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3738 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3739 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3740 | return 0; |
| 3741 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3742 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3745 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3746 | { |
| 3747 | struct nfs_server *server = NFS_SERVER(dir); |
| 3748 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3749 | struct nfs_renameres *res = msg->rpc_resp; |
| 3750 | |
| 3751 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3752 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3753 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3754 | } |
| 3755 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3756 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3757 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3758 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3759 | &data->args.seq_args, |
| 3760 | &data->res.seq_res, |
| 3761 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3765 | struct inode *new_dir) |
| 3766 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3767 | struct nfs_renamedata *data = task->tk_calldata; |
| 3768 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3769 | |
| 3770 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3771 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3772 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3773 | return 0; |
| 3774 | |
| 3775 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3776 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3777 | return 1; |
| 3778 | } |
| 3779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3781 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3782 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | struct nfs4_link_arg arg = { |
| 3784 | .fh = NFS_FH(inode), |
| 3785 | .dir_fh = NFS_FH(dir), |
| 3786 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3787 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3789 | struct nfs4_link_res res = { |
| 3790 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3791 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3792 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | struct rpc_message msg = { |
| 3794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3795 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3796 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3798 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3800 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3801 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3802 | goto out; |
| 3803 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3804 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3805 | if (IS_ERR(res.label)) { |
| 3806 | status = PTR_ERR(res.label); |
| 3807 | goto out; |
| 3808 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3809 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3810 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3811 | 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] | 3812 | if (!status) { |
| 3813 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3814 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3815 | if (!status) |
| 3816 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3817 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3818 | |
| 3819 | |
| 3820 | nfs4_label_free(res.label); |
| 3821 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3822 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3823 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | return status; |
| 3825 | } |
| 3826 | |
| 3827 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3828 | { |
| 3829 | struct nfs4_exception exception = { }; |
| 3830 | int err; |
| 3831 | do { |
| 3832 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3833 | _nfs4_proc_link(inode, dir, name), |
| 3834 | &exception); |
| 3835 | } while (exception.retry); |
| 3836 | return err; |
| 3837 | } |
| 3838 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3839 | struct nfs4_createdata { |
| 3840 | struct rpc_message msg; |
| 3841 | struct nfs4_create_arg arg; |
| 3842 | struct nfs4_create_res res; |
| 3843 | struct nfs_fh fh; |
| 3844 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3845 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3846 | }; |
| 3847 | |
| 3848 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3849 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3850 | { |
| 3851 | struct nfs4_createdata *data; |
| 3852 | |
| 3853 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3854 | if (data != NULL) { |
| 3855 | struct nfs_server *server = NFS_SERVER(dir); |
| 3856 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3857 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3858 | if (IS_ERR(data->label)) |
| 3859 | goto out_free; |
| 3860 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3861 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3862 | data->msg.rpc_argp = &data->arg; |
| 3863 | data->msg.rpc_resp = &data->res; |
| 3864 | data->arg.dir_fh = NFS_FH(dir); |
| 3865 | data->arg.server = server; |
| 3866 | data->arg.name = name; |
| 3867 | data->arg.attrs = sattr; |
| 3868 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3869 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3870 | data->res.server = server; |
| 3871 | data->res.fh = &data->fh; |
| 3872 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3873 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3874 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3875 | } |
| 3876 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3877 | out_free: |
| 3878 | kfree(data); |
| 3879 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3883 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3884 | 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] | 3885 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3886 | if (status == 0) { |
| 3887 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3888 | 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] | 3889 | } |
| 3890 | return status; |
| 3891 | } |
| 3892 | |
| 3893 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3894 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3895 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3896 | kfree(data); |
| 3897 | } |
| 3898 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3899 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3900 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3901 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3903 | struct nfs4_createdata *data; |
| 3904 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3906 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3907 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3908 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3909 | status = -ENOMEM; |
| 3910 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3911 | if (data == NULL) |
| 3912 | goto out; |
| 3913 | |
| 3914 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3915 | data->arg.u.symlink.pages = &page; |
| 3916 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3917 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3919 | status = nfs4_do_create(dir, dentry, data); |
| 3920 | |
| 3921 | nfs4_free_createdata(data); |
| 3922 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | return status; |
| 3924 | } |
| 3925 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3926 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3927 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | { |
| 3929 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3930 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3932 | |
| 3933 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3936 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3937 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3938 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | &exception); |
| 3940 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3941 | |
| 3942 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | return err; |
| 3944 | } |
| 3945 | |
| 3946 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3947 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3949 | struct nfs4_createdata *data; |
| 3950 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3952 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3953 | if (data == NULL) |
| 3954 | goto out; |
| 3955 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3956 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3957 | status = nfs4_do_create(dir, dentry, data); |
| 3958 | |
| 3959 | nfs4_free_createdata(data); |
| 3960 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | return status; |
| 3962 | } |
| 3963 | |
| 3964 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3965 | struct iattr *sattr) |
| 3966 | { |
| 3967 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3968 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3970 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3971 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3972 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3973 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3975 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3976 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3977 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | &exception); |
| 3979 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3980 | nfs4_label_release_security(label); |
| 3981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | return err; |
| 3983 | } |
| 3984 | |
| 3985 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3986 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3988 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | struct nfs4_readdir_arg args = { |
| 3990 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3991 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | .pgbase = 0, |
| 3993 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3994 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3995 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | }; |
| 3997 | struct nfs4_readdir_res res; |
| 3998 | struct rpc_message msg = { |
| 3999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4000 | .rpc_argp = &args, |
| 4001 | .rpc_resp = &res, |
| 4002 | .rpc_cred = cred, |
| 4003 | }; |
| 4004 | int status; |
| 4005 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4006 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4007 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4008 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4009 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4011 | 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] | 4012 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4013 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4014 | status += args.pgbase; |
| 4015 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4016 | |
| 4017 | nfs_invalidate_atime(dir); |
| 4018 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4019 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | return status; |
| 4021 | } |
| 4022 | |
| 4023 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4024 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | { |
| 4026 | struct nfs4_exception exception = { }; |
| 4027 | int err; |
| 4028 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4029 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4030 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4031 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4032 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | &exception); |
| 4034 | } while (exception.retry); |
| 4035 | return err; |
| 4036 | } |
| 4037 | |
| 4038 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4039 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4041 | struct nfs4_createdata *data; |
| 4042 | int mode = sattr->ia_mode; |
| 4043 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4045 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4046 | if (data == NULL) |
| 4047 | goto out; |
| 4048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4050 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4052 | data->arg.ftype = NF4BLK; |
| 4053 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4054 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | } |
| 4056 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4057 | data->arg.ftype = NF4CHR; |
| 4058 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4059 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4060 | } else if (!S_ISSOCK(mode)) { |
| 4061 | status = -EINVAL; |
| 4062 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4064 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4065 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4066 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4067 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4068 | nfs4_free_createdata(data); |
| 4069 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | return status; |
| 4071 | } |
| 4072 | |
| 4073 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4074 | struct iattr *sattr, dev_t rdev) |
| 4075 | { |
| 4076 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4077 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4079 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4080 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4081 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4082 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4084 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4085 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4086 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | &exception); |
| 4088 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4089 | |
| 4090 | nfs4_label_release_security(label); |
| 4091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | return err; |
| 4093 | } |
| 4094 | |
| 4095 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4096 | struct nfs_fsstat *fsstat) |
| 4097 | { |
| 4098 | struct nfs4_statfs_arg args = { |
| 4099 | .fh = fhandle, |
| 4100 | .bitmask = server->attr_bitmask, |
| 4101 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4102 | struct nfs4_statfs_res res = { |
| 4103 | .fsstat = fsstat, |
| 4104 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | struct rpc_message msg = { |
| 4106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4107 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4108 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | }; |
| 4110 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4111 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4112 | 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] | 4113 | } |
| 4114 | |
| 4115 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4116 | { |
| 4117 | struct nfs4_exception exception = { }; |
| 4118 | int err; |
| 4119 | do { |
| 4120 | err = nfs4_handle_exception(server, |
| 4121 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4122 | &exception); |
| 4123 | } while (exception.retry); |
| 4124 | return err; |
| 4125 | } |
| 4126 | |
| 4127 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4128 | struct nfs_fsinfo *fsinfo) |
| 4129 | { |
| 4130 | struct nfs4_fsinfo_arg args = { |
| 4131 | .fh = fhandle, |
| 4132 | .bitmask = server->attr_bitmask, |
| 4133 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4134 | struct nfs4_fsinfo_res res = { |
| 4135 | .fsinfo = fsinfo, |
| 4136 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | struct rpc_message msg = { |
| 4138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4139 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4140 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | }; |
| 4142 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4143 | 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] | 4144 | } |
| 4145 | |
| 4146 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4147 | { |
| 4148 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4149 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | int err; |
| 4151 | |
| 4152 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4153 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4154 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4155 | if (err == 0) { |
| 4156 | struct nfs_client *clp = server->nfs_client; |
| 4157 | |
| 4158 | spin_lock(&clp->cl_lock); |
| 4159 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4160 | clp->cl_last_renewal = now; |
| 4161 | spin_unlock(&clp->cl_lock); |
| 4162 | break; |
| 4163 | } |
| 4164 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } while (exception.retry); |
| 4166 | return err; |
| 4167 | } |
| 4168 | |
| 4169 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4170 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4171 | int error; |
| 4172 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4173 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4174 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4175 | if (error == 0) { |
| 4176 | /* block layout checks this! */ |
| 4177 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4178 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4179 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4180 | |
| 4181 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4185 | struct nfs_pathconf *pathconf) |
| 4186 | { |
| 4187 | struct nfs4_pathconf_arg args = { |
| 4188 | .fh = fhandle, |
| 4189 | .bitmask = server->attr_bitmask, |
| 4190 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4191 | struct nfs4_pathconf_res res = { |
| 4192 | .pathconf = pathconf, |
| 4193 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | struct rpc_message msg = { |
| 4195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4196 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4197 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | }; |
| 4199 | |
| 4200 | /* None of the pathconf attributes are mandatory to implement */ |
| 4201 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4202 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4203 | return 0; |
| 4204 | } |
| 4205 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4206 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4207 | 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] | 4208 | } |
| 4209 | |
| 4210 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4211 | struct nfs_pathconf *pathconf) |
| 4212 | { |
| 4213 | struct nfs4_exception exception = { }; |
| 4214 | int err; |
| 4215 | |
| 4216 | do { |
| 4217 | err = nfs4_handle_exception(server, |
| 4218 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4219 | &exception); |
| 4220 | } while (exception.retry); |
| 4221 | return err; |
| 4222 | } |
| 4223 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4224 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4225 | const struct nfs_open_context *ctx, |
| 4226 | const struct nfs_lock_context *l_ctx, |
| 4227 | fmode_t fmode) |
| 4228 | { |
| 4229 | const struct nfs_lockowner *lockowner = NULL; |
| 4230 | |
| 4231 | if (l_ctx != NULL) |
| 4232 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4233 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4234 | } |
| 4235 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4236 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4237 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4238 | const struct nfs_open_context *ctx, |
| 4239 | const struct nfs_lock_context *l_ctx, |
| 4240 | fmode_t fmode) |
| 4241 | { |
| 4242 | nfs4_stateid current_stateid; |
| 4243 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4244 | /* If the current stateid represents a lost lock, then exit */ |
| 4245 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4246 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4247 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4248 | } |
| 4249 | |
| 4250 | static bool nfs4_error_stateid_expired(int err) |
| 4251 | { |
| 4252 | switch (err) { |
| 4253 | case -NFS4ERR_DELEG_REVOKED: |
| 4254 | case -NFS4ERR_ADMIN_REVOKED: |
| 4255 | case -NFS4ERR_BAD_STATEID: |
| 4256 | case -NFS4ERR_STALE_STATEID: |
| 4257 | case -NFS4ERR_OLD_STATEID: |
| 4258 | case -NFS4ERR_OPENMODE: |
| 4259 | case -NFS4ERR_EXPIRED: |
| 4260 | return true; |
| 4261 | } |
| 4262 | return false; |
| 4263 | } |
| 4264 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4265 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4266 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4267 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4268 | } |
| 4269 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4270 | 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] | 4271 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4272 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4274 | trace_nfs4_read(hdr, task->tk_status); |
| 4275 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4276 | hdr->args.context->state, |
| 4277 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4278 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4279 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4281 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4282 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4284 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4285 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4288 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4289 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4290 | { |
| 4291 | |
| 4292 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4293 | nfs4_stateid_is_current(&args->stateid, |
| 4294 | args->context, |
| 4295 | args->lock_context, |
| 4296 | FMODE_READ)) |
| 4297 | return false; |
| 4298 | rpc_restart_call_prepare(task); |
| 4299 | return true; |
| 4300 | } |
| 4301 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4302 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4303 | { |
| 4304 | |
| 4305 | dprintk("--> %s\n", __func__); |
| 4306 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4307 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4308 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4309 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4310 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4311 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4312 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4315 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4316 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4318 | hdr->timestamp = jiffies; |
| 4319 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4320 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4321 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4324 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4325 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4326 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4327 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4328 | &hdr->args.seq_args, |
| 4329 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4330 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4331 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4332 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4333 | hdr->args.lock_context, |
| 4334 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4335 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4336 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4337 | return -EIO; |
| 4338 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4341 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4342 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4344 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4345 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4346 | trace_nfs4_write(hdr, task->tk_status); |
| 4347 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4348 | hdr->args.context->state, |
| 4349 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4350 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4351 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4353 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4354 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4355 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4356 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4357 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4360 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4361 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4362 | { |
| 4363 | |
| 4364 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4365 | nfs4_stateid_is_current(&args->stateid, |
| 4366 | args->context, |
| 4367 | args->lock_context, |
| 4368 | FMODE_WRITE)) |
| 4369 | return false; |
| 4370 | rpc_restart_call_prepare(task); |
| 4371 | return true; |
| 4372 | } |
| 4373 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4374 | 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] | 4375 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4376 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4377 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4378 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4379 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4380 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4381 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4384 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4385 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4386 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4387 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4388 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4389 | return false; |
| 4390 | /* Otherwise, request attributes if and only if we don't hold |
| 4391 | * a delegation |
| 4392 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4393 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4394 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4395 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4396 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4397 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4399 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4400 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4401 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4402 | hdr->args.bitmask = NULL; |
| 4403 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4404 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4405 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4406 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4407 | if (!hdr->pgio_done_cb) |
| 4408 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4409 | hdr->res.server = server; |
| 4410 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4412 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4413 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4416 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4417 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4418 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4419 | &data->args.seq_args, |
| 4420 | &data->res.seq_res, |
| 4421 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4424 | 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] | 4425 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4427 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4428 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4429 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4430 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4431 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4432 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4434 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4437 | 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] | 4438 | { |
| 4439 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4440 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4441 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4444 | 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] | 4445 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4446 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4447 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4448 | if (data->commit_done_cb == NULL) |
| 4449 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4450 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4451 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4452 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4455 | struct nfs4_renewdata { |
| 4456 | struct nfs_client *client; |
| 4457 | unsigned long timestamp; |
| 4458 | }; |
| 4459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | /* |
| 4461 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4462 | * standalone procedure for queueing an asynchronous RENEW. |
| 4463 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4464 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4465 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4466 | struct nfs4_renewdata *data = calldata; |
| 4467 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4468 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4469 | if (atomic_read(&clp->cl_count) > 1) |
| 4470 | nfs4_schedule_state_renewal(clp); |
| 4471 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4472 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4473 | } |
| 4474 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4475 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4477 | struct nfs4_renewdata *data = calldata; |
| 4478 | struct nfs_client *clp = data->client; |
| 4479 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4481 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4482 | switch (task->tk_status) { |
| 4483 | case 0: |
| 4484 | break; |
| 4485 | case -NFS4ERR_LEASE_MOVED: |
| 4486 | nfs4_schedule_lease_moved_recovery(clp); |
| 4487 | break; |
| 4488 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4489 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4490 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4491 | return; |
| 4492 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4493 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4494 | return; |
| 4495 | } |
| 4496 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4498 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4501 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4502 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4503 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4504 | }; |
| 4505 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4506 | 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] | 4507 | { |
| 4508 | struct rpc_message msg = { |
| 4509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4510 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4511 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4513 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4515 | if (renew_flags == 0) |
| 4516 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4517 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4518 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4519 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4520 | if (data == NULL) |
| 4521 | return -ENOMEM; |
| 4522 | data->client = clp; |
| 4523 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4524 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4525 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4528 | 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] | 4529 | { |
| 4530 | struct rpc_message msg = { |
| 4531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4532 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4533 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | }; |
| 4535 | unsigned long now = jiffies; |
| 4536 | int status; |
| 4537 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4538 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | if (status < 0) |
| 4540 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4541 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | return 0; |
| 4543 | } |
| 4544 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4545 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4546 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4547 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4550 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4551 | * 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] | 4552 | * the stack. |
| 4553 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4554 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4555 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4556 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4557 | struct page **pages, unsigned int *pgbase) |
| 4558 | { |
| 4559 | struct page *newpage, **spages; |
| 4560 | int rc = 0; |
| 4561 | size_t len; |
| 4562 | spages = pages; |
| 4563 | |
| 4564 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4565 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4566 | newpage = alloc_page(GFP_KERNEL); |
| 4567 | |
| 4568 | if (newpage == NULL) |
| 4569 | goto unwind; |
| 4570 | memcpy(page_address(newpage), buf, len); |
| 4571 | buf += len; |
| 4572 | buflen -= len; |
| 4573 | *pages++ = newpage; |
| 4574 | rc++; |
| 4575 | } while (buflen != 0); |
| 4576 | |
| 4577 | return rc; |
| 4578 | |
| 4579 | unwind: |
| 4580 | for(; rc > 0; rc--) |
| 4581 | __free_page(spages[rc-1]); |
| 4582 | return -ENOMEM; |
| 4583 | } |
| 4584 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4585 | struct nfs4_cached_acl { |
| 4586 | int cached; |
| 4587 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4588 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4589 | }; |
| 4590 | |
| 4591 | 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] | 4592 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4593 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4594 | |
| 4595 | spin_lock(&inode->i_lock); |
| 4596 | kfree(nfsi->nfs4_acl); |
| 4597 | nfsi->nfs4_acl = acl; |
| 4598 | spin_unlock(&inode->i_lock); |
| 4599 | } |
| 4600 | |
| 4601 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4602 | { |
| 4603 | nfs4_set_cached_acl(inode, NULL); |
| 4604 | } |
| 4605 | |
| 4606 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4607 | { |
| 4608 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4609 | struct nfs4_cached_acl *acl; |
| 4610 | int ret = -ENOENT; |
| 4611 | |
| 4612 | spin_lock(&inode->i_lock); |
| 4613 | acl = nfsi->nfs4_acl; |
| 4614 | if (acl == NULL) |
| 4615 | goto out; |
| 4616 | if (buf == NULL) /* user is just asking for length */ |
| 4617 | goto out_len; |
| 4618 | if (acl->cached == 0) |
| 4619 | goto out; |
| 4620 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4621 | if (acl->len > buflen) |
| 4622 | goto out; |
| 4623 | memcpy(buf, acl->data, acl->len); |
| 4624 | out_len: |
| 4625 | ret = acl->len; |
| 4626 | out: |
| 4627 | spin_unlock(&inode->i_lock); |
| 4628 | return ret; |
| 4629 | } |
| 4630 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4631 | 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] | 4632 | { |
| 4633 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4634 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4635 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4636 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4637 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4638 | if (acl == NULL) |
| 4639 | goto out; |
| 4640 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4641 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4642 | } else { |
| 4643 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4644 | if (acl == NULL) |
| 4645 | goto out; |
| 4646 | acl->cached = 0; |
| 4647 | } |
| 4648 | acl->len = acl_len; |
| 4649 | out: |
| 4650 | nfs4_set_cached_acl(inode, acl); |
| 4651 | } |
| 4652 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4653 | /* |
| 4654 | * The getxattr API returns the required buffer length when called with a |
| 4655 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4656 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4657 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4658 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4659 | * the cache. If not so, we throw away the page, and cache the required |
| 4660 | * length. The next getxattr call will then produce another round trip to |
| 4661 | * the server, this time with the input buf of the required size. |
| 4662 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4663 | 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] | 4664 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4665 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4666 | struct nfs_getaclargs args = { |
| 4667 | .fh = NFS_FH(inode), |
| 4668 | .acl_pages = pages, |
| 4669 | .acl_len = buflen, |
| 4670 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4671 | struct nfs_getaclres res = { |
| 4672 | .acl_len = buflen, |
| 4673 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4674 | struct rpc_message msg = { |
| 4675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4676 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4677 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4678 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4679 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4680 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4681 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4682 | /* As long as we're doing a round trip to the server anyway, |
| 4683 | * let's be prepared for a page of acl data. */ |
| 4684 | if (npages == 0) |
| 4685 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4686 | if (npages > ARRAY_SIZE(pages)) |
| 4687 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4688 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4689 | for (i = 0; i < npages; i++) { |
| 4690 | pages[i] = alloc_page(GFP_KERNEL); |
| 4691 | if (!pages[i]) |
| 4692 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4693 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4694 | |
| 4695 | /* for decoding across pages */ |
| 4696 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4697 | if (!res.acl_scratch) |
| 4698 | goto out_free; |
| 4699 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4700 | args.acl_len = npages * PAGE_SIZE; |
| 4701 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4702 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4703 | 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] | 4704 | __func__, buf, buflen, npages, args.acl_len); |
| 4705 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4706 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4707 | if (ret) |
| 4708 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4709 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4710 | /* Handle the case where the passed-in buffer is too short */ |
| 4711 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4712 | /* Did the user only issue a request for the acl length? */ |
| 4713 | if (buf == NULL) |
| 4714 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4715 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4716 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4717 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4718 | 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] | 4719 | if (buf) { |
| 4720 | if (res.acl_len > buflen) { |
| 4721 | ret = -ERANGE; |
| 4722 | goto out_free; |
| 4723 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4724 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4725 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4726 | out_ok: |
| 4727 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4728 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4729 | for (i = 0; i < npages; i++) |
| 4730 | if (pages[i]) |
| 4731 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4732 | if (res.acl_scratch) |
| 4733 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4734 | return ret; |
| 4735 | } |
| 4736 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4737 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4738 | { |
| 4739 | struct nfs4_exception exception = { }; |
| 4740 | ssize_t ret; |
| 4741 | do { |
| 4742 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4743 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4744 | if (ret >= 0) |
| 4745 | break; |
| 4746 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4747 | } while (exception.retry); |
| 4748 | return ret; |
| 4749 | } |
| 4750 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4751 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4752 | { |
| 4753 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4754 | int ret; |
| 4755 | |
| 4756 | if (!nfs4_server_supports_acls(server)) |
| 4757 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4758 | ret = nfs_revalidate_inode(server, inode); |
| 4759 | if (ret < 0) |
| 4760 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4761 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4762 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4763 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4764 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4765 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4766 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4767 | return ret; |
| 4768 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4771 | 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] | 4772 | { |
| 4773 | struct nfs_server *server = NFS_SERVER(inode); |
| 4774 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4775 | struct nfs_setaclargs arg = { |
| 4776 | .fh = NFS_FH(inode), |
| 4777 | .acl_pages = pages, |
| 4778 | .acl_len = buflen, |
| 4779 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4780 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4781 | struct rpc_message msg = { |
| 4782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4783 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4784 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4785 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4786 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4787 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4788 | |
| 4789 | if (!nfs4_server_supports_acls(server)) |
| 4790 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4791 | if (npages > ARRAY_SIZE(pages)) |
| 4792 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4793 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4794 | if (i < 0) |
| 4795 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4796 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4797 | 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] | 4798 | |
| 4799 | /* |
| 4800 | * Free each page after tx, so the only ref left is |
| 4801 | * held by the network stack |
| 4802 | */ |
| 4803 | for (; i > 0; i--) |
| 4804 | put_page(pages[i-1]); |
| 4805 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4806 | /* |
| 4807 | * Acl update can result in inode attribute update. |
| 4808 | * so mark the attribute cache invalid. |
| 4809 | */ |
| 4810 | spin_lock(&inode->i_lock); |
| 4811 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4812 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4813 | nfs_access_zap_cache(inode); |
| 4814 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4815 | return ret; |
| 4816 | } |
| 4817 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4818 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4819 | { |
| 4820 | struct nfs4_exception exception = { }; |
| 4821 | int err; |
| 4822 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4823 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4824 | trace_nfs4_set_acl(inode, err); |
| 4825 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4826 | &exception); |
| 4827 | } while (exception.retry); |
| 4828 | return err; |
| 4829 | } |
| 4830 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4831 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4832 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4833 | size_t buflen) |
| 4834 | { |
| 4835 | struct nfs_server *server = NFS_SERVER(inode); |
| 4836 | struct nfs_fattr fattr; |
| 4837 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4838 | |
| 4839 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4840 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4841 | .fh = NFS_FH(inode), |
| 4842 | .bitmask = bitmask, |
| 4843 | }; |
| 4844 | struct nfs4_getattr_res res = { |
| 4845 | .fattr = &fattr, |
| 4846 | .label = &label, |
| 4847 | .server = server, |
| 4848 | }; |
| 4849 | struct rpc_message msg = { |
| 4850 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4851 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4852 | .rpc_resp = &res, |
| 4853 | }; |
| 4854 | int ret; |
| 4855 | |
| 4856 | nfs_fattr_init(&fattr); |
| 4857 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4858 | 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] | 4859 | if (ret) |
| 4860 | return ret; |
| 4861 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4862 | return -ENOENT; |
| 4863 | if (buflen < label.len) |
| 4864 | return -ERANGE; |
| 4865 | return 0; |
| 4866 | } |
| 4867 | |
| 4868 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4869 | size_t buflen) |
| 4870 | { |
| 4871 | struct nfs4_exception exception = { }; |
| 4872 | int err; |
| 4873 | |
| 4874 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4875 | return -EOPNOTSUPP; |
| 4876 | |
| 4877 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4878 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4879 | trace_nfs4_get_security_label(inode, err); |
| 4880 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4881 | &exception); |
| 4882 | } while (exception.retry); |
| 4883 | return err; |
| 4884 | } |
| 4885 | |
| 4886 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4887 | struct nfs4_label *ilabel, |
| 4888 | struct nfs_fattr *fattr, |
| 4889 | struct nfs4_label *olabel) |
| 4890 | { |
| 4891 | |
| 4892 | struct iattr sattr = {0}; |
| 4893 | struct nfs_server *server = NFS_SERVER(inode); |
| 4894 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4895 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4896 | .fh = NFS_FH(inode), |
| 4897 | .iap = &sattr, |
| 4898 | .server = server, |
| 4899 | .bitmask = bitmask, |
| 4900 | .label = ilabel, |
| 4901 | }; |
| 4902 | struct nfs_setattrres res = { |
| 4903 | .fattr = fattr, |
| 4904 | .label = olabel, |
| 4905 | .server = server, |
| 4906 | }; |
| 4907 | struct rpc_message msg = { |
| 4908 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4909 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4910 | .rpc_resp = &res, |
| 4911 | }; |
| 4912 | int status; |
| 4913 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4914 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4915 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4916 | 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] | 4917 | if (status) |
| 4918 | dprintk("%s failed: %d\n", __func__, status); |
| 4919 | |
| 4920 | return status; |
| 4921 | } |
| 4922 | |
| 4923 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4924 | struct nfs4_label *ilabel, |
| 4925 | struct nfs_fattr *fattr, |
| 4926 | struct nfs4_label *olabel) |
| 4927 | { |
| 4928 | struct nfs4_exception exception = { }; |
| 4929 | int err; |
| 4930 | |
| 4931 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4932 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4933 | fattr, olabel); |
| 4934 | trace_nfs4_set_security_label(inode, err); |
| 4935 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4936 | &exception); |
| 4937 | } while (exception.retry); |
| 4938 | return err; |
| 4939 | } |
| 4940 | |
| 4941 | static int |
| 4942 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4943 | { |
| 4944 | struct nfs4_label ilabel, *olabel = NULL; |
| 4945 | struct nfs_fattr fattr; |
| 4946 | struct rpc_cred *cred; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4947 | struct inode *inode = d_inode(dentry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4948 | int status; |
| 4949 | |
| 4950 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4951 | return -EOPNOTSUPP; |
| 4952 | |
| 4953 | nfs_fattr_init(&fattr); |
| 4954 | |
| 4955 | ilabel.pi = 0; |
| 4956 | ilabel.lfs = 0; |
| 4957 | ilabel.label = (char *)buf; |
| 4958 | ilabel.len = buflen; |
| 4959 | |
| 4960 | cred = rpc_lookup_cred(); |
| 4961 | if (IS_ERR(cred)) |
| 4962 | return PTR_ERR(cred); |
| 4963 | |
| 4964 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4965 | if (IS_ERR(olabel)) { |
| 4966 | status = -PTR_ERR(olabel); |
| 4967 | goto out; |
| 4968 | } |
| 4969 | |
| 4970 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4971 | if (status == 0) |
| 4972 | nfs_setsecurity(inode, &fattr, olabel); |
| 4973 | |
| 4974 | nfs4_label_free(olabel); |
| 4975 | out: |
| 4976 | put_rpccred(cred); |
| 4977 | return status; |
| 4978 | } |
| 4979 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4980 | |
| 4981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | static int |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 4983 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4984 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4986 | struct nfs_client *clp = server->nfs_client; |
| 4987 | |
| 4988 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | return 0; |
| 4990 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4991 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4992 | case -NFS4ERR_ADMIN_REVOKED: |
| 4993 | case -NFS4ERR_BAD_STATEID: |
| 4994 | case -NFS4ERR_OPENMODE: |
| 4995 | if (state == NULL) |
| 4996 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4997 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4998 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4999 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5000 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5001 | if (state != NULL) { |
| 5002 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 5003 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5004 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5006 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5007 | nfs4_schedule_lease_recovery(clp); |
| 5008 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 5009 | case -NFS4ERR_MOVED: |
| 5010 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 5011 | goto recovery_failed; |
| 5012 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 5013 | case -NFS4ERR_LEASE_MOVED: |
| 5014 | nfs4_schedule_lease_moved_recovery(clp); |
| 5015 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 5016 | #if defined(CONFIG_NFS_V4_1) |
| 5017 | case -NFS4ERR_BADSESSION: |
| 5018 | case -NFS4ERR_BADSLOT: |
| 5019 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5020 | case -NFS4ERR_DEADSESSION: |
| 5021 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5022 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 5023 | case -NFS4ERR_SEQ_MISORDERED: |
| 5024 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 5025 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5026 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 5027 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 5028 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5030 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5031 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 5032 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 5033 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5035 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 5037 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | } |
| 5039 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 5040 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 5041 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5042 | task->tk_status = -EIO; |
| 5043 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5044 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5045 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5046 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 5047 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 5048 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 5049 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 5050 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5051 | task->tk_status = 0; |
| 5052 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5055 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5056 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5057 | { |
| 5058 | __be32 verf[2]; |
| 5059 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5060 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5061 | /* An impossible timestamp guarantees this value |
| 5062 | * will never match a generated boot time. */ |
| 5063 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5064 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5065 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5066 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5067 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5068 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5069 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5070 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5071 | } |
| 5072 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5073 | static int |
| 5074 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5075 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5076 | int result; |
| 5077 | size_t len; |
| 5078 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5079 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5080 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5081 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5082 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5083 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5084 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5085 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5086 | 1 + |
| 5087 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5088 | 1; |
| 5089 | rcu_read_unlock(); |
| 5090 | |
| 5091 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5092 | return -EINVAL; |
| 5093 | |
| 5094 | /* |
| 5095 | * Since this string is allocated at mount time, and held until the |
| 5096 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5097 | * about a memory-reclaim deadlock. |
| 5098 | */ |
| 5099 | str = kmalloc(len, GFP_KERNEL); |
| 5100 | if (!str) |
| 5101 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5102 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5103 | rcu_read_lock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5104 | result = scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
| 5105 | clp->cl_ipaddr, |
| 5106 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5107 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5108 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5109 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5110 | clp->cl_owner_id = str; |
| 5111 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5112 | } |
| 5113 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5114 | static int |
| 5115 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5116 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5117 | int result; |
| 5118 | size_t len; |
| 5119 | char *str; |
| 5120 | |
| 5121 | len = 10 + 10 + 1 + 10 + 1 + |
| 5122 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5123 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5124 | |
| 5125 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5126 | return -EINVAL; |
| 5127 | |
| 5128 | /* |
| 5129 | * Since this string is allocated at mount time, and held until the |
| 5130 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5131 | * about a memory-reclaim deadlock. |
| 5132 | */ |
| 5133 | str = kmalloc(len, GFP_KERNEL); |
| 5134 | if (!str) |
| 5135 | return -ENOMEM; |
| 5136 | |
| 5137 | result = scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 5138 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5139 | nfs4_client_id_uniquifier, |
| 5140 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5141 | clp->cl_owner_id = str; |
| 5142 | return 0; |
| 5143 | } |
| 5144 | |
| 5145 | static int |
| 5146 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5147 | { |
| 5148 | int result; |
| 5149 | size_t len; |
| 5150 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5151 | |
| 5152 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5153 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5154 | |
| 5155 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5156 | return nfs4_init_uniquifier_client_string(clp); |
| 5157 | |
| 5158 | len = 10 + 10 + 1 + 10 + 1 + |
| 5159 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5160 | |
| 5161 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5162 | return -EINVAL; |
| 5163 | |
| 5164 | /* |
| 5165 | * Since this string is allocated at mount time, and held until the |
| 5166 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5167 | * about a memory-reclaim deadlock. |
| 5168 | */ |
| 5169 | str = kmalloc(len, GFP_KERNEL); |
| 5170 | if (!str) |
| 5171 | return -ENOMEM; |
| 5172 | |
| 5173 | result = scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 5174 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5175 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5176 | clp->cl_owner_id = str; |
| 5177 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5178 | } |
| 5179 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5180 | /* |
| 5181 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5182 | * services. Advertise one based on the address family of the |
| 5183 | * clientaddr. |
| 5184 | */ |
| 5185 | static unsigned int |
| 5186 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5187 | { |
| 5188 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5189 | return scnprintf(buf, len, "tcp6"); |
| 5190 | else |
| 5191 | return scnprintf(buf, len, "tcp"); |
| 5192 | } |
| 5193 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5194 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5195 | { |
| 5196 | struct nfs4_setclientid *sc = calldata; |
| 5197 | |
| 5198 | if (task->tk_status == 0) |
| 5199 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5200 | } |
| 5201 | |
| 5202 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5203 | .rpc_call_done = nfs4_setclientid_done, |
| 5204 | }; |
| 5205 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5206 | /** |
| 5207 | * nfs4_proc_setclientid - Negotiate client ID |
| 5208 | * @clp: state data structure |
| 5209 | * @program: RPC program for NFSv4 callback service |
| 5210 | * @port: IP port number for NFS4 callback service |
| 5211 | * @cred: RPC credential to use for this call |
| 5212 | * @res: where to place the result |
| 5213 | * |
| 5214 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5215 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5216 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5217 | unsigned short port, struct rpc_cred *cred, |
| 5218 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | { |
| 5220 | nfs4_verifier sc_verifier; |
| 5221 | struct nfs4_setclientid setclientid = { |
| 5222 | .sc_verifier = &sc_verifier, |
| 5223 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5224 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | }; |
| 5226 | struct rpc_message msg = { |
| 5227 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5228 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5229 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5230 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5232 | struct rpc_task *task; |
| 5233 | struct rpc_task_setup task_setup_data = { |
| 5234 | .rpc_client = clp->cl_rpcclient, |
| 5235 | .rpc_message = &msg, |
| 5236 | .callback_ops = &nfs4_setclientid_ops, |
| 5237 | .callback_data = &setclientid, |
| 5238 | .flags = RPC_TASK_TIMEOUT, |
| 5239 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5240 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5242 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5243 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5244 | |
| 5245 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5246 | status = nfs4_init_uniform_client_string(clp); |
| 5247 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5248 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5249 | |
| 5250 | if (status) |
| 5251 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5252 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5253 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5254 | setclientid.sc_netid_len = |
| 5255 | nfs4_init_callback_netid(clp, |
| 5256 | setclientid.sc_netid, |
| 5257 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5258 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5259 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5261 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5262 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5263 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5264 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5265 | task = rpc_run_task(&task_setup_data); |
| 5266 | if (IS_ERR(task)) { |
| 5267 | status = PTR_ERR(task); |
| 5268 | goto out; |
| 5269 | } |
| 5270 | status = task->tk_status; |
| 5271 | if (setclientid.sc_cred) { |
| 5272 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5273 | put_rpccred(setclientid.sc_cred); |
| 5274 | } |
| 5275 | rpc_put_task(task); |
| 5276 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5277 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5278 | dprintk("NFS reply setclientid: %d\n", status); |
| 5279 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5282 | /** |
| 5283 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5284 | * @clp: state data structure |
| 5285 | * @res: result of a previous SETCLIENTID |
| 5286 | * @cred: RPC credential to use for this call |
| 5287 | * |
| 5288 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5289 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5290 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5291 | struct nfs4_setclientid_res *arg, |
| 5292 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | struct rpc_message msg = { |
| 5295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5296 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5297 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | int status; |
| 5300 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5301 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5302 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5303 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5304 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5305 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5306 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | return status; |
| 5308 | } |
| 5309 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5310 | struct nfs4_delegreturndata { |
| 5311 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5312 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5313 | struct nfs_fh fh; |
| 5314 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5315 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5316 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5317 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5318 | struct inode *inode; |
| 5319 | bool roc; |
| 5320 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5321 | }; |
| 5322 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5323 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5324 | { |
| 5325 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5326 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5327 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5328 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5329 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5330 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5331 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5332 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5333 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5334 | case -NFS4ERR_ADMIN_REVOKED: |
| 5335 | case -NFS4ERR_DELEG_REVOKED: |
| 5336 | case -NFS4ERR_BAD_STATEID: |
| 5337 | case -NFS4ERR_OLD_STATEID: |
| 5338 | case -NFS4ERR_STALE_STATEID: |
| 5339 | case -NFS4ERR_EXPIRED: |
| 5340 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5341 | if (data->roc) |
| 5342 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5343 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5344 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5345 | if (nfs4_async_handle_error(task, data->res.server, |
| 5346 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5347 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5348 | return; |
| 5349 | } |
| 5350 | } |
| 5351 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | static void nfs4_delegreturn_release(void *calldata) |
| 5355 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5356 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5357 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5358 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5359 | if (inode) { |
| 5360 | if (data->roc) |
| 5361 | pnfs_roc_release(inode); |
| 5362 | nfs_iput_and_deactive(inode); |
| 5363 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5364 | kfree(calldata); |
| 5365 | } |
| 5366 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5367 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5368 | { |
| 5369 | struct nfs4_delegreturndata *d_data; |
| 5370 | |
| 5371 | d_data = (struct nfs4_delegreturndata *)data; |
| 5372 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5373 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5374 | return; |
| 5375 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5376 | if (d_data->roc) |
| 5377 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5378 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5379 | nfs4_setup_sequence(d_data->res.server, |
| 5380 | &d_data->args.seq_args, |
| 5381 | &d_data->res.seq_res, |
| 5382 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5383 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5384 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5385 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5386 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5387 | .rpc_call_done = nfs4_delegreturn_done, |
| 5388 | .rpc_release = nfs4_delegreturn_release, |
| 5389 | }; |
| 5390 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5391 | 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] | 5392 | { |
| 5393 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5394 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5395 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5396 | struct rpc_message msg = { |
| 5397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5398 | .rpc_cred = cred, |
| 5399 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5400 | struct rpc_task_setup task_setup_data = { |
| 5401 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5402 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5403 | .callback_ops = &nfs4_delegreturn_ops, |
| 5404 | .flags = RPC_TASK_ASYNC, |
| 5405 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5406 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5407 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5408 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5409 | if (data == NULL) |
| 5410 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5411 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5412 | data->args.fhandle = &data->fh; |
| 5413 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5414 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5415 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5416 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5417 | data->res.fattr = &data->fattr; |
| 5418 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5419 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5420 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5421 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5422 | data->inode = nfs_igrab_and_active(inode); |
| 5423 | if (data->inode) |
| 5424 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5425 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5426 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5427 | msg.rpc_argp = &data->args; |
| 5428 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5429 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5430 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5431 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5432 | if (!issync) |
| 5433 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5434 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5435 | if (status != 0) |
| 5436 | goto out; |
| 5437 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5438 | if (status == 0) |
| 5439 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5440 | else |
| 5441 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5442 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5443 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5444 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5447 | 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] | 5448 | { |
| 5449 | struct nfs_server *server = NFS_SERVER(inode); |
| 5450 | struct nfs4_exception exception = { }; |
| 5451 | int err; |
| 5452 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5453 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5454 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | switch (err) { |
| 5456 | case -NFS4ERR_STALE_STATEID: |
| 5457 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | case 0: |
| 5459 | return 0; |
| 5460 | } |
| 5461 | err = nfs4_handle_exception(server, err, &exception); |
| 5462 | } while (exception.retry); |
| 5463 | return err; |
| 5464 | } |
| 5465 | |
| 5466 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5467 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5468 | |
| 5469 | /* |
| 5470 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5471 | */ |
| 5472 | static unsigned long |
| 5473 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5474 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5475 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | timeout <<= 1; |
| 5477 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5478 | return NFS4_LOCK_MAXTIMEOUT; |
| 5479 | return timeout; |
| 5480 | } |
| 5481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5483 | { |
| 5484 | struct inode *inode = state->inode; |
| 5485 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5486 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5487 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5489 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5491 | struct nfs_lockt_res res = { |
| 5492 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | }; |
| 5494 | struct rpc_message msg = { |
| 5495 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5496 | .rpc_argp = &arg, |
| 5497 | .rpc_resp = &res, |
| 5498 | .rpc_cred = state->owner->so_cred, |
| 5499 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | struct nfs4_lock_state *lsp; |
| 5501 | int status; |
| 5502 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5503 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5504 | status = nfs4_set_lock_state(state, request); |
| 5505 | if (status != 0) |
| 5506 | goto out; |
| 5507 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5508 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5509 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5510 | 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] | 5511 | switch (status) { |
| 5512 | case 0: |
| 5513 | request->fl_type = F_UNLCK; |
| 5514 | break; |
| 5515 | case -NFS4ERR_DENIED: |
| 5516 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5518 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5519 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5520 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | return status; |
| 5522 | } |
| 5523 | |
| 5524 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5525 | { |
| 5526 | struct nfs4_exception exception = { }; |
| 5527 | int err; |
| 5528 | |
| 5529 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5530 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5531 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5532 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | &exception); |
| 5534 | } while (exception.retry); |
| 5535 | return err; |
| 5536 | } |
| 5537 | |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5538 | static int do_vfs_lock(struct inode *inode, struct file_lock *fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | { |
| 5540 | int res = 0; |
| 5541 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5542 | case FL_POSIX: |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5543 | res = posix_lock_inode_wait(inode, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | break; |
| 5545 | case FL_FLOCK: |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5546 | res = flock_lock_inode_wait(inode, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | break; |
| 5548 | default: |
| 5549 | BUG(); |
| 5550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5551 | return res; |
| 5552 | } |
| 5553 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5554 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5555 | struct nfs_locku_args arg; |
| 5556 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5557 | struct nfs4_lock_state *lsp; |
| 5558 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5559 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5560 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5561 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5562 | }; |
| 5563 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5564 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5565 | struct nfs_open_context *ctx, |
| 5566 | struct nfs4_lock_state *lsp, |
| 5567 | struct nfs_seqid *seqid) |
| 5568 | { |
| 5569 | struct nfs4_unlockdata *p; |
| 5570 | struct inode *inode = lsp->ls_state->inode; |
| 5571 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5572 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5573 | if (p == NULL) |
| 5574 | return NULL; |
| 5575 | p->arg.fh = NFS_FH(inode); |
| 5576 | p->arg.fl = &p->fl; |
| 5577 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5578 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5579 | p->lsp = lsp; |
| 5580 | atomic_inc(&lsp->ls_count); |
| 5581 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5582 | p->ctx = get_nfs_open_context(ctx); |
| 5583 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5584 | p->server = NFS_SERVER(inode); |
| 5585 | return p; |
| 5586 | } |
| 5587 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5588 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5589 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5590 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5591 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5592 | nfs4_put_lock_state(calldata->lsp); |
| 5593 | put_nfs_open_context(calldata->ctx); |
| 5594 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5595 | } |
| 5596 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5597 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5598 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5599 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5600 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5601 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5602 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5603 | switch (task->tk_status) { |
| 5604 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5605 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5606 | do_vfs_lock(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5607 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5608 | &calldata->res.stateid)) |
| 5609 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5610 | case -NFS4ERR_BAD_STATEID: |
| 5611 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5612 | case -NFS4ERR_STALE_STATEID: |
| 5613 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5614 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5615 | &calldata->lsp->ls_stateid)) |
| 5616 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5617 | break; |
| 5618 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5619 | if (nfs4_async_handle_error(task, calldata->server, |
| 5620 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5621 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5622 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5623 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5626 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5627 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5628 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5630 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5631 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5632 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5633 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5634 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5635 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5636 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5637 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5638 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5639 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5640 | &calldata->res.seq_res, |
| 5641 | task) != 0) |
| 5642 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5643 | return; |
| 5644 | out_no_action: |
| 5645 | task->tk_action = NULL; |
| 5646 | out_wait: |
| 5647 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5650 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5651 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5652 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5653 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5654 | }; |
| 5655 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5656 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5657 | struct nfs_open_context *ctx, |
| 5658 | struct nfs4_lock_state *lsp, |
| 5659 | struct nfs_seqid *seqid) |
| 5660 | { |
| 5661 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5662 | struct rpc_message msg = { |
| 5663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5664 | .rpc_cred = ctx->cred, |
| 5665 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5666 | struct rpc_task_setup task_setup_data = { |
| 5667 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5668 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5669 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5670 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5671 | .flags = RPC_TASK_ASYNC, |
| 5672 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5673 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5674 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5675 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5676 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5677 | /* Ensure this is an unlock - when canceling a lock, the |
| 5678 | * canceled lock is passed in, and it won't be an unlock. |
| 5679 | */ |
| 5680 | fl->fl_type = F_UNLCK; |
| 5681 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5682 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5683 | if (data == NULL) { |
| 5684 | nfs_free_seqid(seqid); |
| 5685 | return ERR_PTR(-ENOMEM); |
| 5686 | } |
| 5687 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5688 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5689 | msg.rpc_argp = &data->arg; |
| 5690 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5691 | task_setup_data.callback_data = data; |
| 5692 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5696 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5697 | struct inode *inode = state->inode; |
| 5698 | struct nfs4_state_owner *sp = state->owner; |
| 5699 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5700 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5701 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5702 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5703 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5704 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5705 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5707 | status = nfs4_set_lock_state(state, request); |
| 5708 | /* Unlock _before_ we do the RPC call */ |
| 5709 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5710 | /* Exclude nfs_delegation_claim_locks() */ |
| 5711 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5712 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5713 | down_read(&nfsi->rwsem); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5714 | if (do_vfs_lock(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5715 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5716 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5717 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5718 | } |
| 5719 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5720 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5721 | if (status != 0) |
| 5722 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5723 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5724 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5725 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5726 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5727 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5728 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5729 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5730 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5731 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5732 | 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] | 5733 | status = PTR_ERR(task); |
| 5734 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5735 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5736 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5737 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5738 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5739 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5740 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5741 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5744 | struct nfs4_lockdata { |
| 5745 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5746 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5747 | struct nfs4_lock_state *lsp; |
| 5748 | struct nfs_open_context *ctx; |
| 5749 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5750 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5751 | int rpc_status; |
| 5752 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5753 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5754 | }; |
| 5755 | |
| 5756 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5757 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5758 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5759 | { |
| 5760 | struct nfs4_lockdata *p; |
| 5761 | struct inode *inode = lsp->ls_state->inode; |
| 5762 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5763 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5764 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5765 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5766 | if (p == NULL) |
| 5767 | return NULL; |
| 5768 | |
| 5769 | p->arg.fh = NFS_FH(inode); |
| 5770 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5771 | 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] | 5772 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5773 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5774 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5775 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5776 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5777 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5778 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5779 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5780 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5781 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5782 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5783 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5784 | atomic_inc(&lsp->ls_count); |
| 5785 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5786 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5787 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5788 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5789 | out_free_seqid: |
| 5790 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5791 | out_free: |
| 5792 | kfree(p); |
| 5793 | return NULL; |
| 5794 | } |
| 5795 | |
| 5796 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5797 | { |
| 5798 | struct nfs4_lockdata *data = calldata; |
| 5799 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5801 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5802 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5803 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5804 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5805 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5806 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5807 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5808 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5809 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5810 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5811 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5812 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5813 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5814 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5815 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5816 | &data->lsp->ls_stateid); |
| 5817 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5818 | if (!nfs4_valid_open_stateid(state)) { |
| 5819 | data->rpc_status = -EBADF; |
| 5820 | task->tk_action = NULL; |
| 5821 | goto out_release_open_seqid; |
| 5822 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5823 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5824 | if (nfs4_setup_sequence(data->server, |
| 5825 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5826 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5827 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5828 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5829 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5830 | nfs_release_seqid(data->arg.open_seqid); |
| 5831 | out_release_lock_seqid: |
| 5832 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5833 | out_wait: |
| 5834 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5835 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5836 | } |
| 5837 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5838 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5839 | { |
| 5840 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5841 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5842 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5843 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5844 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5845 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5846 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5847 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5848 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5849 | switch (task->tk_status) { |
| 5850 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5851 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5852 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5853 | if (data->arg.new_lock) { |
| 5854 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5855 | if (do_vfs_lock(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5856 | rpc_restart_call_prepare(task); |
| 5857 | break; |
| 5858 | } |
| 5859 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5860 | if (data->arg.new_lock_owner != 0) { |
| 5861 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5862 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5863 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5864 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5865 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5866 | break; |
| 5867 | case -NFS4ERR_BAD_STATEID: |
| 5868 | case -NFS4ERR_OLD_STATEID: |
| 5869 | case -NFS4ERR_STALE_STATEID: |
| 5870 | case -NFS4ERR_EXPIRED: |
| 5871 | if (data->arg.new_lock_owner != 0) { |
| 5872 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5873 | &lsp->ls_state->open_stateid)) |
| 5874 | rpc_restart_call_prepare(task); |
| 5875 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5876 | &lsp->ls_stateid)) |
| 5877 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5878 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5879 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | static void nfs4_lock_release(void *calldata) |
| 5883 | { |
| 5884 | struct nfs4_lockdata *data = calldata; |
| 5885 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5886 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5887 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5888 | if (data->cancelled != 0) { |
| 5889 | struct rpc_task *task; |
| 5890 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5891 | data->arg.lock_seqid); |
| 5892 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5893 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5894 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5895 | } else |
| 5896 | nfs_free_seqid(data->arg.lock_seqid); |
| 5897 | nfs4_put_lock_state(data->lsp); |
| 5898 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5899 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5900 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5901 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5905 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5906 | .rpc_call_done = nfs4_lock_done, |
| 5907 | .rpc_release = nfs4_lock_release, |
| 5908 | }; |
| 5909 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5910 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5911 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5912 | switch (error) { |
| 5913 | case -NFS4ERR_ADMIN_REVOKED: |
| 5914 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5915 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5916 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5917 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5918 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5919 | break; |
| 5920 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5921 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5922 | case -NFS4ERR_EXPIRED: |
| 5923 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5924 | }; |
| 5925 | } |
| 5926 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5927 | 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] | 5928 | { |
| 5929 | struct nfs4_lockdata *data; |
| 5930 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5931 | struct rpc_message msg = { |
| 5932 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5933 | .rpc_cred = state->owner->so_cred, |
| 5934 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5935 | struct rpc_task_setup task_setup_data = { |
| 5936 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5937 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5938 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5939 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5940 | .flags = RPC_TASK_ASYNC, |
| 5941 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5942 | int ret; |
| 5943 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5944 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5945 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5946 | fl->fl_u.nfs4_fl.owner, |
| 5947 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5948 | if (data == NULL) |
| 5949 | return -ENOMEM; |
| 5950 | if (IS_SETLKW(cmd)) |
| 5951 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5952 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5953 | msg.rpc_argp = &data->arg; |
| 5954 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5955 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5956 | if (recovery_type > NFS_LOCK_NEW) { |
| 5957 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5958 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5959 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5960 | } else |
| 5961 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5962 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5963 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5964 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5965 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5966 | if (ret == 0) { |
| 5967 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5968 | if (ret) |
| 5969 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5970 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5971 | } else |
| 5972 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5973 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5974 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5975 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5979 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5980 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5981 | struct nfs4_exception exception = { |
| 5982 | .inode = state->inode, |
| 5983 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5984 | int err; |
| 5985 | |
| 5986 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5987 | /* Cache the lock if possible... */ |
| 5988 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5989 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5990 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5991 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5992 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5993 | break; |
| 5994 | nfs4_handle_exception(server, err, &exception); |
| 5995 | } while (exception.retry); |
| 5996 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6000 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6001 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6002 | struct nfs4_exception exception = { |
| 6003 | .inode = state->inode, |
| 6004 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6005 | int err; |
| 6006 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6007 | err = nfs4_set_lock_state(state, request); |
| 6008 | if (err != 0) |
| 6009 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6010 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6011 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6012 | return 0; |
| 6013 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6014 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6015 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6016 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6017 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6018 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6019 | switch (err) { |
| 6020 | default: |
| 6021 | goto out; |
| 6022 | case -NFS4ERR_GRACE: |
| 6023 | case -NFS4ERR_DELAY: |
| 6024 | nfs4_handle_exception(server, err, &exception); |
| 6025 | err = 0; |
| 6026 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6027 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6028 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6029 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6032 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6033 | /** |
| 6034 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6035 | * |
| 6036 | * @state: NFSv4 state for an inode |
| 6037 | * |
| 6038 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6039 | * Otherwise a negative NFS4ERR value is returned. |
| 6040 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6041 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6042 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6043 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6044 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6045 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6046 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6047 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6048 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6049 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6050 | |
| 6051 | status = nfs41_test_stateid(server, |
| 6052 | &lsp->ls_stateid, |
| 6053 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6054 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6055 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6056 | /* Free the stateid unless the server |
| 6057 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 6058 | if (status != -NFS4ERR_BAD_STATEID) |
| 6059 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6060 | &lsp->ls_stateid, |
| 6061 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6062 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6063 | ret = status; |
| 6064 | } |
| 6065 | } |
| 6066 | }; |
| 6067 | |
| 6068 | return ret; |
| 6069 | } |
| 6070 | |
| 6071 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6072 | { |
| 6073 | int status = NFS_OK; |
| 6074 | |
| 6075 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6076 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6077 | if (status != NFS_OK) |
| 6078 | status = nfs4_lock_expired(state, request); |
| 6079 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6080 | } |
| 6081 | #endif |
| 6082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6084 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6085 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6086 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6087 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6089 | if ((fl_flags & FL_POSIX) && |
| 6090 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6091 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6092 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6093 | status = nfs4_set_lock_state(state, request); |
| 6094 | if (status != 0) |
| 6095 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6096 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6097 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6098 | if (status < 0) |
| 6099 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6100 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6101 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6102 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6103 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6104 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6105 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6106 | up_read(&nfsi->rwsem); |
| 6107 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6108 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6109 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6110 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6111 | out: |
| 6112 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | return status; |
| 6114 | } |
| 6115 | |
| 6116 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6117 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6118 | struct nfs4_exception exception = { |
| 6119 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6120 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6121 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | int err; |
| 6123 | |
| 6124 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6125 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6126 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6127 | if (err == -NFS4ERR_DENIED) |
| 6128 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6129 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6130 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6131 | } while (exception.retry); |
| 6132 | return err; |
| 6133 | } |
| 6134 | |
| 6135 | static int |
| 6136 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6137 | { |
| 6138 | struct nfs_open_context *ctx; |
| 6139 | struct nfs4_state *state; |
| 6140 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6141 | int status; |
| 6142 | |
| 6143 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6144 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | state = ctx->state; |
| 6146 | |
| 6147 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6148 | return -EINVAL; |
| 6149 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6150 | if (IS_GETLK(cmd)) { |
| 6151 | if (state != NULL) |
| 6152 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6153 | return 0; |
| 6154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | |
| 6156 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6157 | return -EINVAL; |
| 6158 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6159 | if (request->fl_type == F_UNLCK) { |
| 6160 | if (state != NULL) |
| 6161 | return nfs4_proc_unlck(state, cmd, request); |
| 6162 | return 0; |
| 6163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6164 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6165 | if (state == NULL) |
| 6166 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6167 | /* |
| 6168 | * Don't rely on the VFS having checked the file open mode, |
| 6169 | * since it won't do this for flock() locks. |
| 6170 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6171 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6172 | case F_RDLCK: |
| 6173 | if (!(filp->f_mode & FMODE_READ)) |
| 6174 | return -EBADF; |
| 6175 | break; |
| 6176 | case F_WRLCK: |
| 6177 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6178 | return -EBADF; |
| 6179 | } |
| 6180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | do { |
| 6182 | status = nfs4_proc_setlk(state, cmd, request); |
| 6183 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6184 | break; |
| 6185 | timeout = nfs4_set_lock_task_retry(timeout); |
| 6186 | status = -ERESTARTSYS; |
| 6187 | if (signalled()) |
| 6188 | break; |
| 6189 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6190 | return status; |
| 6191 | } |
| 6192 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6193 | 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] | 6194 | { |
| 6195 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6196 | int err; |
| 6197 | |
| 6198 | err = nfs4_set_lock_state(state, fl); |
| 6199 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6200 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6201 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6202 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6203 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6204 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6205 | struct nfs_release_lockowner_data { |
| 6206 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6207 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6208 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6209 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6210 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6211 | }; |
| 6212 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6213 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6214 | { |
| 6215 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6216 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6217 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6218 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6219 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6220 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6221 | } |
| 6222 | |
| 6223 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6224 | { |
| 6225 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6226 | struct nfs_server *server = data->server; |
| 6227 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6228 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6229 | |
| 6230 | switch (task->tk_status) { |
| 6231 | case 0: |
| 6232 | renew_lease(server, data->timestamp); |
| 6233 | break; |
| 6234 | case -NFS4ERR_STALE_CLIENTID: |
| 6235 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6236 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6237 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6238 | case -NFS4ERR_LEASE_MOVED: |
| 6239 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6240 | if (nfs4_async_handle_error(task, server, |
| 6241 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6242 | rpc_restart_call_prepare(task); |
| 6243 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6244 | } |
| 6245 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6246 | static void nfs4_release_lockowner_release(void *calldata) |
| 6247 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6248 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6249 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6250 | kfree(calldata); |
| 6251 | } |
| 6252 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6253 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6254 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6255 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6256 | .rpc_release = nfs4_release_lockowner_release, |
| 6257 | }; |
| 6258 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6259 | static void |
| 6260 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6261 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6262 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6263 | struct rpc_message msg = { |
| 6264 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6265 | }; |
| 6266 | |
| 6267 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6268 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6269 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6270 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6271 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6272 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6273 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6274 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6275 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6276 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6277 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6278 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6279 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6280 | msg.rpc_resp = &data->res; |
| 6281 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6282 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6283 | } |
| 6284 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6285 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6286 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6287 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6288 | const void *buf, size_t buflen, |
| 6289 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6290 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6291 | if (strcmp(key, "") != 0) |
| 6292 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6293 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6294 | return nfs4_proc_set_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6295 | } |
| 6296 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6297 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6298 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6299 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6300 | if (strcmp(key, "") != 0) |
| 6301 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6302 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6303 | return nfs4_proc_get_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6306 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6307 | size_t list_len, const char *name, |
| 6308 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6309 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6310 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6311 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6312 | if (!nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry)))) |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6313 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6314 | |
| 6315 | if (list && len <= list_len) |
| 6316 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6317 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6320 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6321 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6322 | { |
| 6323 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6324 | } |
| 6325 | |
| 6326 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6327 | const void *buf, size_t buflen, |
| 6328 | int flags, int type) |
| 6329 | { |
| 6330 | if (security_ismaclabel(key)) |
| 6331 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6332 | |
| 6333 | return -EOPNOTSUPP; |
| 6334 | } |
| 6335 | |
| 6336 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6337 | void *buf, size_t buflen, int type) |
| 6338 | { |
| 6339 | if (security_ismaclabel(key)) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6340 | return nfs4_get_security_label(d_inode(dentry), buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6341 | return -EOPNOTSUPP; |
| 6342 | } |
| 6343 | |
| 6344 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6345 | size_t list_len, const char *name, |
| 6346 | size_t name_len, int type) |
| 6347 | { |
| 6348 | size_t len = 0; |
| 6349 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6350 | if (nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) { |
| 6351 | len = security_inode_listsecurity(d_inode(dentry), NULL, 0); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6352 | if (list && len <= list_len) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6353 | security_inode_listsecurity(d_inode(dentry), list, len); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6354 | } |
| 6355 | return len; |
| 6356 | } |
| 6357 | |
| 6358 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6359 | .prefix = XATTR_SECURITY_PREFIX, |
| 6360 | .list = nfs4_xattr_list_nfs4_label, |
| 6361 | .get = nfs4_xattr_get_nfs4_label, |
| 6362 | .set = nfs4_xattr_set_nfs4_label, |
| 6363 | }; |
| 6364 | #endif |
| 6365 | |
| 6366 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6367 | /* |
| 6368 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6369 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6370 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6371 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6372 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6373 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6374 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6375 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6376 | return; |
| 6377 | |
| 6378 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6379 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6380 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6381 | fattr->nlink = 2; |
| 6382 | } |
| 6383 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6384 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6385 | const struct qstr *name, |
| 6386 | struct nfs4_fs_locations *fs_locations, |
| 6387 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6388 | { |
| 6389 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6390 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6391 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6392 | }; |
| 6393 | struct nfs4_fs_locations_arg args = { |
| 6394 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6395 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6396 | .page = page, |
| 6397 | .bitmask = bitmask, |
| 6398 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6399 | struct nfs4_fs_locations_res res = { |
| 6400 | .fs_locations = fs_locations, |
| 6401 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6402 | struct rpc_message msg = { |
| 6403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6404 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6405 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6406 | }; |
| 6407 | int status; |
| 6408 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6409 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6410 | |
| 6411 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6412 | * is not supported */ |
| 6413 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6414 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6415 | else |
| 6416 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6417 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6418 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6419 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6420 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6421 | 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] | 6422 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6423 | return status; |
| 6424 | } |
| 6425 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6426 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6427 | const struct qstr *name, |
| 6428 | struct nfs4_fs_locations *fs_locations, |
| 6429 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6430 | { |
| 6431 | struct nfs4_exception exception = { }; |
| 6432 | int err; |
| 6433 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6434 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6435 | fs_locations, page); |
| 6436 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6437 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6438 | &exception); |
| 6439 | } while (exception.retry); |
| 6440 | return err; |
| 6441 | } |
| 6442 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6443 | /* |
| 6444 | * This operation also signals the server that this client is |
| 6445 | * performing migration recovery. The server can stop returning |
| 6446 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6447 | * appended to this compound to identify the client ID which is |
| 6448 | * performing recovery. |
| 6449 | */ |
| 6450 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6451 | struct nfs4_fs_locations *locations, |
| 6452 | struct page *page, struct rpc_cred *cred) |
| 6453 | { |
| 6454 | struct nfs_server *server = NFS_SERVER(inode); |
| 6455 | struct rpc_clnt *clnt = server->client; |
| 6456 | u32 bitmask[2] = { |
| 6457 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6458 | }; |
| 6459 | struct nfs4_fs_locations_arg args = { |
| 6460 | .clientid = server->nfs_client->cl_clientid, |
| 6461 | .fh = NFS_FH(inode), |
| 6462 | .page = page, |
| 6463 | .bitmask = bitmask, |
| 6464 | .migration = 1, /* skip LOOKUP */ |
| 6465 | .renew = 1, /* append RENEW */ |
| 6466 | }; |
| 6467 | struct nfs4_fs_locations_res res = { |
| 6468 | .fs_locations = locations, |
| 6469 | .migration = 1, |
| 6470 | .renew = 1, |
| 6471 | }; |
| 6472 | struct rpc_message msg = { |
| 6473 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6474 | .rpc_argp = &args, |
| 6475 | .rpc_resp = &res, |
| 6476 | .rpc_cred = cred, |
| 6477 | }; |
| 6478 | unsigned long now = jiffies; |
| 6479 | int status; |
| 6480 | |
| 6481 | nfs_fattr_init(&locations->fattr); |
| 6482 | locations->server = server; |
| 6483 | locations->nlocations = 0; |
| 6484 | |
| 6485 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6486 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6487 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6488 | &args.seq_args, &res.seq_res); |
| 6489 | if (status) |
| 6490 | return status; |
| 6491 | |
| 6492 | renew_lease(server, now); |
| 6493 | return 0; |
| 6494 | } |
| 6495 | |
| 6496 | #ifdef CONFIG_NFS_V4_1 |
| 6497 | |
| 6498 | /* |
| 6499 | * This operation also signals the server that this client is |
| 6500 | * performing migration recovery. The server can stop asserting |
| 6501 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6502 | * performing this operation is identified in the SEQUENCE |
| 6503 | * operation in this compound. |
| 6504 | * |
| 6505 | * When the client supports GETATTR(fs_locations_info), it can |
| 6506 | * be plumbed in here. |
| 6507 | */ |
| 6508 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6509 | struct nfs4_fs_locations *locations, |
| 6510 | struct page *page, struct rpc_cred *cred) |
| 6511 | { |
| 6512 | struct nfs_server *server = NFS_SERVER(inode); |
| 6513 | struct rpc_clnt *clnt = server->client; |
| 6514 | u32 bitmask[2] = { |
| 6515 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6516 | }; |
| 6517 | struct nfs4_fs_locations_arg args = { |
| 6518 | .fh = NFS_FH(inode), |
| 6519 | .page = page, |
| 6520 | .bitmask = bitmask, |
| 6521 | .migration = 1, /* skip LOOKUP */ |
| 6522 | }; |
| 6523 | struct nfs4_fs_locations_res res = { |
| 6524 | .fs_locations = locations, |
| 6525 | .migration = 1, |
| 6526 | }; |
| 6527 | struct rpc_message msg = { |
| 6528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6529 | .rpc_argp = &args, |
| 6530 | .rpc_resp = &res, |
| 6531 | .rpc_cred = cred, |
| 6532 | }; |
| 6533 | int status; |
| 6534 | |
| 6535 | nfs_fattr_init(&locations->fattr); |
| 6536 | locations->server = server; |
| 6537 | locations->nlocations = 0; |
| 6538 | |
| 6539 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6540 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6541 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6542 | &args.seq_args, &res.seq_res); |
| 6543 | if (status == NFS4_OK && |
| 6544 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6545 | status = -NFS4ERR_LEASE_MOVED; |
| 6546 | return status; |
| 6547 | } |
| 6548 | |
| 6549 | #endif /* CONFIG_NFS_V4_1 */ |
| 6550 | |
| 6551 | /** |
| 6552 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6553 | * @inode: inode on FSID that is migrating |
| 6554 | * @locations: result of query |
| 6555 | * @page: buffer |
| 6556 | * @cred: credential to use for this operation |
| 6557 | * |
| 6558 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6559 | * operation failed, or a negative errno if a local error occurred. |
| 6560 | * |
| 6561 | * On success, "locations" is filled in, but if the server has |
| 6562 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6563 | * asserted. |
| 6564 | * |
| 6565 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6566 | * from this client that require migration recovery. |
| 6567 | */ |
| 6568 | int nfs4_proc_get_locations(struct inode *inode, |
| 6569 | struct nfs4_fs_locations *locations, |
| 6570 | struct page *page, struct rpc_cred *cred) |
| 6571 | { |
| 6572 | struct nfs_server *server = NFS_SERVER(inode); |
| 6573 | struct nfs_client *clp = server->nfs_client; |
| 6574 | const struct nfs4_mig_recovery_ops *ops = |
| 6575 | clp->cl_mvops->mig_recovery_ops; |
| 6576 | struct nfs4_exception exception = { }; |
| 6577 | int status; |
| 6578 | |
| 6579 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6580 | (unsigned long long)server->fsid.major, |
| 6581 | (unsigned long long)server->fsid.minor, |
| 6582 | clp->cl_hostname); |
| 6583 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6584 | |
| 6585 | do { |
| 6586 | status = ops->get_locations(inode, locations, page, cred); |
| 6587 | if (status != -NFS4ERR_DELAY) |
| 6588 | break; |
| 6589 | nfs4_handle_exception(server, status, &exception); |
| 6590 | } while (exception.retry); |
| 6591 | return status; |
| 6592 | } |
| 6593 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6594 | /* |
| 6595 | * This operation also signals the server that this client is |
| 6596 | * performing "lease moved" recovery. The server can stop |
| 6597 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6598 | * is appended to this compound to identify the client ID which is |
| 6599 | * performing recovery. |
| 6600 | */ |
| 6601 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6602 | { |
| 6603 | struct nfs_server *server = NFS_SERVER(inode); |
| 6604 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6605 | struct rpc_clnt *clnt = server->client; |
| 6606 | struct nfs4_fsid_present_arg args = { |
| 6607 | .fh = NFS_FH(inode), |
| 6608 | .clientid = clp->cl_clientid, |
| 6609 | .renew = 1, /* append RENEW */ |
| 6610 | }; |
| 6611 | struct nfs4_fsid_present_res res = { |
| 6612 | .renew = 1, |
| 6613 | }; |
| 6614 | struct rpc_message msg = { |
| 6615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6616 | .rpc_argp = &args, |
| 6617 | .rpc_resp = &res, |
| 6618 | .rpc_cred = cred, |
| 6619 | }; |
| 6620 | unsigned long now = jiffies; |
| 6621 | int status; |
| 6622 | |
| 6623 | res.fh = nfs_alloc_fhandle(); |
| 6624 | if (res.fh == NULL) |
| 6625 | return -ENOMEM; |
| 6626 | |
| 6627 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6628 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6629 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6630 | &args.seq_args, &res.seq_res); |
| 6631 | nfs_free_fhandle(res.fh); |
| 6632 | if (status) |
| 6633 | return status; |
| 6634 | |
| 6635 | do_renew_lease(clp, now); |
| 6636 | return 0; |
| 6637 | } |
| 6638 | |
| 6639 | #ifdef CONFIG_NFS_V4_1 |
| 6640 | |
| 6641 | /* |
| 6642 | * This operation also signals the server that this client is |
| 6643 | * performing "lease moved" recovery. The server can stop asserting |
| 6644 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6645 | * this operation is identified in the SEQUENCE operation in this |
| 6646 | * compound. |
| 6647 | */ |
| 6648 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6649 | { |
| 6650 | struct nfs_server *server = NFS_SERVER(inode); |
| 6651 | struct rpc_clnt *clnt = server->client; |
| 6652 | struct nfs4_fsid_present_arg args = { |
| 6653 | .fh = NFS_FH(inode), |
| 6654 | }; |
| 6655 | struct nfs4_fsid_present_res res = { |
| 6656 | }; |
| 6657 | struct rpc_message msg = { |
| 6658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6659 | .rpc_argp = &args, |
| 6660 | .rpc_resp = &res, |
| 6661 | .rpc_cred = cred, |
| 6662 | }; |
| 6663 | int status; |
| 6664 | |
| 6665 | res.fh = nfs_alloc_fhandle(); |
| 6666 | if (res.fh == NULL) |
| 6667 | return -ENOMEM; |
| 6668 | |
| 6669 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6670 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6671 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6672 | &args.seq_args, &res.seq_res); |
| 6673 | nfs_free_fhandle(res.fh); |
| 6674 | if (status == NFS4_OK && |
| 6675 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6676 | status = -NFS4ERR_LEASE_MOVED; |
| 6677 | return status; |
| 6678 | } |
| 6679 | |
| 6680 | #endif /* CONFIG_NFS_V4_1 */ |
| 6681 | |
| 6682 | /** |
| 6683 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6684 | * @inode: inode on FSID to check |
| 6685 | * @cred: credential to use for this operation |
| 6686 | * |
| 6687 | * Server indicates whether the FSID is present, moved, or not |
| 6688 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6689 | * condition for this client ID. |
| 6690 | * |
| 6691 | * Returns NFS4_OK if the FSID is present on this server, |
| 6692 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6693 | * NFS4ERR code if some error occurred on the server, or a |
| 6694 | * negative errno if a local failure occurred. |
| 6695 | */ |
| 6696 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6697 | { |
| 6698 | struct nfs_server *server = NFS_SERVER(inode); |
| 6699 | struct nfs_client *clp = server->nfs_client; |
| 6700 | const struct nfs4_mig_recovery_ops *ops = |
| 6701 | clp->cl_mvops->mig_recovery_ops; |
| 6702 | struct nfs4_exception exception = { }; |
| 6703 | int status; |
| 6704 | |
| 6705 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6706 | (unsigned long long)server->fsid.major, |
| 6707 | (unsigned long long)server->fsid.minor, |
| 6708 | clp->cl_hostname); |
| 6709 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6710 | |
| 6711 | do { |
| 6712 | status = ops->fsid_present(inode, cred); |
| 6713 | if (status != -NFS4ERR_DELAY) |
| 6714 | break; |
| 6715 | nfs4_handle_exception(server, status, &exception); |
| 6716 | } while (exception.retry); |
| 6717 | return status; |
| 6718 | } |
| 6719 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6720 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6721 | * If 'use_integrity' is true and the state managment nfs_client |
| 6722 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6723 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6724 | * Considerations sections. Otherwise, just use the user cred with the |
| 6725 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6726 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6727 | 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] | 6728 | { |
| 6729 | int status; |
| 6730 | struct nfs4_secinfo_arg args = { |
| 6731 | .dir_fh = NFS_FH(dir), |
| 6732 | .name = name, |
| 6733 | }; |
| 6734 | struct nfs4_secinfo_res res = { |
| 6735 | .flavors = flavors, |
| 6736 | }; |
| 6737 | struct rpc_message msg = { |
| 6738 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6739 | .rpc_argp = &args, |
| 6740 | .rpc_resp = &res, |
| 6741 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6742 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6743 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6744 | |
| 6745 | if (use_integrity) { |
| 6746 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6747 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6748 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6749 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6750 | |
| 6751 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6752 | |
| 6753 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6754 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6755 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6756 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6757 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6758 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6759 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6760 | if (cred) |
| 6761 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6762 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6763 | return status; |
| 6764 | } |
| 6765 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6766 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6767 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6768 | { |
| 6769 | struct nfs4_exception exception = { }; |
| 6770 | int err; |
| 6771 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6772 | err = -NFS4ERR_WRONGSEC; |
| 6773 | |
| 6774 | /* try to use integrity protection with machine cred */ |
| 6775 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6776 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6777 | |
| 6778 | /* |
| 6779 | * if unable to use integrity protection, or SECINFO with |
| 6780 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6781 | * disallowed by spec, but exists in deployed servers) use |
| 6782 | * the current filesystem's rpc_client and the user cred. |
| 6783 | */ |
| 6784 | if (err == -NFS4ERR_WRONGSEC) |
| 6785 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6786 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6787 | trace_nfs4_secinfo(dir, name, err); |
| 6788 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6789 | &exception); |
| 6790 | } while (exception.retry); |
| 6791 | return err; |
| 6792 | } |
| 6793 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6794 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6795 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6796 | * Check the exchange flags returned by the server for invalid flags, having |
| 6797 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6798 | * DS flags set. |
| 6799 | */ |
| 6800 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6801 | { |
| 6802 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6803 | goto out_inval; |
| 6804 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6805 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6806 | goto out_inval; |
| 6807 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6808 | goto out_inval; |
| 6809 | return NFS_OK; |
| 6810 | out_inval: |
| 6811 | return -NFS4ERR_INVAL; |
| 6812 | } |
| 6813 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6814 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6815 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6816 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6817 | { |
| 6818 | if (a->server_scope_sz == b->server_scope_sz && |
| 6819 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6820 | return true; |
| 6821 | |
| 6822 | return false; |
| 6823 | } |
| 6824 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6825 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6826 | * nfs4_proc_bind_conn_to_session() |
| 6827 | * |
| 6828 | * The 4.1 client currently uses the same TCP connection for the |
| 6829 | * fore and backchannel. |
| 6830 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6831 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6832 | { |
| 6833 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6834 | struct nfs41_bind_conn_to_session_args args = { |
| 6835 | .client = clp, |
| 6836 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6837 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6838 | struct nfs41_bind_conn_to_session_res res; |
| 6839 | struct rpc_message msg = { |
| 6840 | .rpc_proc = |
| 6841 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6842 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6843 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6844 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6845 | }; |
| 6846 | |
| 6847 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6848 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6849 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 6850 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 6851 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6852 | |
| 6853 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6854 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6855 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6856 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6857 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6858 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6859 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6860 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6861 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6862 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6863 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6864 | __func__); |
| 6865 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6866 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6867 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6868 | 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] | 6869 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6870 | __func__); |
| 6871 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6872 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6873 | } |
| 6874 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6875 | out: |
| 6876 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6877 | return status; |
| 6878 | } |
| 6879 | |
| 6880 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6881 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6882 | * 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] | 6883 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6884 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6885 | .how = SP4_MACH_CRED, |
| 6886 | .enforce.u.words = { |
| 6887 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6888 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6889 | 1 << (OP_CREATE_SESSION - 32) | |
| 6890 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6891 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6892 | }, |
| 6893 | .allow.u.words = { |
| 6894 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6895 | 1 << (OP_LOCKU) | |
| 6896 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6897 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6898 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6899 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6900 | 1 << (OP_FREE_STATEID - 32) | |
| 6901 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6902 | } |
| 6903 | }; |
| 6904 | |
| 6905 | /* |
| 6906 | * Select the state protection mode for client `clp' given the server results |
| 6907 | * from exchange_id in `sp'. |
| 6908 | * |
| 6909 | * Returns 0 on success, negative errno otherwise. |
| 6910 | */ |
| 6911 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6912 | struct nfs41_state_protection *sp) |
| 6913 | { |
| 6914 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6915 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6916 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6917 | 1 << (OP_CREATE_SESSION - 32) | |
| 6918 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6919 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6920 | }; |
| 6921 | unsigned int i; |
| 6922 | |
| 6923 | if (sp->how == SP4_MACH_CRED) { |
| 6924 | /* Print state protect result */ |
| 6925 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6926 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6927 | if (test_bit(i, sp->enforce.u.longs)) |
| 6928 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6929 | if (test_bit(i, sp->allow.u.longs)) |
| 6930 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6931 | } |
| 6932 | |
| 6933 | /* make sure nothing is on enforce list that isn't supported */ |
| 6934 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6935 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6936 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6937 | return -EINVAL; |
| 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | /* |
| 6942 | * Minimal mode - state operations are allowed to use machine |
| 6943 | * credential. Note this already happens by default, so the |
| 6944 | * client doesn't have to do anything more than the negotiation. |
| 6945 | * |
| 6946 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6947 | * we're already using the machine cred for exchange_id |
| 6948 | * and will never use a different cred. |
| 6949 | */ |
| 6950 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6951 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6952 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6953 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6954 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6955 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6956 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6957 | } else { |
| 6958 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6959 | return -EINVAL; |
| 6960 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6961 | |
| 6962 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6963 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6964 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6965 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6966 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6967 | |
| 6968 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6969 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6970 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6971 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6972 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6973 | |
| 6974 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6975 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6976 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6977 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6978 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6979 | |
| 6980 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6981 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6982 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6983 | } |
| 6984 | |
| 6985 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6986 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6987 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6988 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | return 0; |
| 6992 | } |
| 6993 | |
| 6994 | /* |
| 6995 | * _nfs4_proc_exchange_id() |
| 6996 | * |
| 6997 | * Wrapper for EXCHANGE_ID operation. |
| 6998 | */ |
| 6999 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7000 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7001 | { |
| 7002 | nfs4_verifier verifier; |
| 7003 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 7004 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7005 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7006 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 7007 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7008 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7009 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7010 | #else |
| 7011 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7012 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7013 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7014 | }; |
| 7015 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7016 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7017 | }; |
| 7018 | int status; |
| 7019 | struct rpc_message msg = { |
| 7020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 7021 | .rpc_argp = &args, |
| 7022 | .rpc_resp = &res, |
| 7023 | .rpc_cred = cred, |
| 7024 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7025 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 7026 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7027 | |
| 7028 | status = nfs4_init_uniform_client_string(clp); |
| 7029 | if (status) |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7030 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7031 | |
| 7032 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7033 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7034 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7035 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7036 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7037 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7038 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7039 | status = -ENOMEM; |
| 7040 | goto out; |
| 7041 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7042 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7043 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7044 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7045 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7046 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7047 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7048 | } |
| 7049 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7050 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7051 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7052 | status = -ENOMEM; |
| 7053 | goto out_server_scope; |
| 7054 | } |
| 7055 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7056 | switch (sp4_how) { |
| 7057 | case SP4_NONE: |
| 7058 | args.state_protect.how = SP4_NONE; |
| 7059 | break; |
| 7060 | |
| 7061 | case SP4_MACH_CRED: |
| 7062 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 7063 | break; |
| 7064 | |
| 7065 | default: |
| 7066 | /* unsupported! */ |
| 7067 | WARN_ON_ONCE(1); |
| 7068 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7069 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7070 | } |
| 7071 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7072 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7073 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7074 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7075 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7076 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7077 | if (status == 0) |
| 7078 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 7079 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7080 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7081 | clp->cl_clientid = res.clientid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7082 | clp->cl_exchange_flags = res.flags; |
| 7083 | /* Client ID is not confirmed */ |
| 7084 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7085 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7086 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7087 | clp->cl_seqid = res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7088 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7089 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7090 | kfree(clp->cl_serverowner); |
| 7091 | clp->cl_serverowner = res.server_owner; |
| 7092 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7093 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7094 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7095 | kfree(clp->cl_implid); |
| 7096 | clp->cl_implid = res.impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7097 | res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7098 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7099 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7100 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7101 | res.server_scope)) { |
| 7102 | dprintk("%s: server_scope mismatch detected\n", |
| 7103 | __func__); |
| 7104 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7105 | kfree(clp->cl_serverscope); |
| 7106 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7107 | } |
| 7108 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7109 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7110 | clp->cl_serverscope = res.server_scope; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7111 | res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7112 | } |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7113 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7114 | |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7115 | out_impl_id: |
| 7116 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7117 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7118 | kfree(res.server_scope); |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7119 | out_server_owner: |
| 7120 | kfree(res.server_owner); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7121 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7122 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7123 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7124 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7125 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7126 | clp->cl_implid->date.seconds, |
| 7127 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7128 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7129 | return status; |
| 7130 | } |
| 7131 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7132 | /* |
| 7133 | * nfs4_proc_exchange_id() |
| 7134 | * |
| 7135 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7136 | * |
| 7137 | * Since the clientid has expired, all compounds using sessions |
| 7138 | * associated with the stale clientid will be returning |
| 7139 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7140 | * be in some phase of session reset. |
| 7141 | * |
| 7142 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7143 | */ |
| 7144 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7145 | { |
| 7146 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7147 | int status; |
| 7148 | |
| 7149 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7150 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7151 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 7152 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 7153 | if (!status) |
| 7154 | return 0; |
| 7155 | } |
| 7156 | |
| 7157 | /* try SP4_NONE */ |
| 7158 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 7159 | } |
| 7160 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7161 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7162 | struct rpc_cred *cred) |
| 7163 | { |
| 7164 | struct rpc_message msg = { |
| 7165 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7166 | .rpc_argp = clp, |
| 7167 | .rpc_cred = cred, |
| 7168 | }; |
| 7169 | int status; |
| 7170 | |
| 7171 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7172 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7173 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7174 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7175 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7176 | return status; |
| 7177 | } |
| 7178 | |
| 7179 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7180 | struct rpc_cred *cred) |
| 7181 | { |
| 7182 | unsigned int loop; |
| 7183 | int ret; |
| 7184 | |
| 7185 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7186 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7187 | switch (ret) { |
| 7188 | case -NFS4ERR_DELAY: |
| 7189 | case -NFS4ERR_CLIENTID_BUSY: |
| 7190 | ssleep(1); |
| 7191 | break; |
| 7192 | default: |
| 7193 | return ret; |
| 7194 | } |
| 7195 | } |
| 7196 | return 0; |
| 7197 | } |
| 7198 | |
| 7199 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7200 | { |
| 7201 | struct rpc_cred *cred; |
| 7202 | int ret = 0; |
| 7203 | |
| 7204 | if (clp->cl_mvops->minor_version < 1) |
| 7205 | goto out; |
| 7206 | if (clp->cl_exchange_flags == 0) |
| 7207 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7208 | if (clp->cl_preserve_clid) |
| 7209 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7210 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7211 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7212 | if (cred) |
| 7213 | put_rpccred(cred); |
| 7214 | switch (ret) { |
| 7215 | case 0: |
| 7216 | case -NFS4ERR_STALE_CLIENTID: |
| 7217 | clp->cl_exchange_flags = 0; |
| 7218 | } |
| 7219 | out: |
| 7220 | return ret; |
| 7221 | } |
| 7222 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7223 | struct nfs4_get_lease_time_data { |
| 7224 | struct nfs4_get_lease_time_args *args; |
| 7225 | struct nfs4_get_lease_time_res *res; |
| 7226 | struct nfs_client *clp; |
| 7227 | }; |
| 7228 | |
| 7229 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7230 | void *calldata) |
| 7231 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7232 | struct nfs4_get_lease_time_data *data = |
| 7233 | (struct nfs4_get_lease_time_data *)calldata; |
| 7234 | |
| 7235 | dprintk("--> %s\n", __func__); |
| 7236 | /* just setup sequence, do not trigger session recovery |
| 7237 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7238 | nfs41_setup_sequence(data->clp->cl_session, |
| 7239 | &data->args->la_seq_args, |
| 7240 | &data->res->lr_seq_res, |
| 7241 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7242 | dprintk("<-- %s\n", __func__); |
| 7243 | } |
| 7244 | |
| 7245 | /* |
| 7246 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7247 | * from sequence operation or clientid errors. |
| 7248 | */ |
| 7249 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7250 | { |
| 7251 | struct nfs4_get_lease_time_data *data = |
| 7252 | (struct nfs4_get_lease_time_data *)calldata; |
| 7253 | |
| 7254 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7255 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7256 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7257 | switch (task->tk_status) { |
| 7258 | case -NFS4ERR_DELAY: |
| 7259 | case -NFS4ERR_GRACE: |
| 7260 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7261 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7262 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7263 | /* fall through */ |
| 7264 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7265 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7266 | return; |
| 7267 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7268 | dprintk("<-- %s\n", __func__); |
| 7269 | } |
| 7270 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7271 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7272 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7273 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7274 | }; |
| 7275 | |
| 7276 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7277 | { |
| 7278 | struct rpc_task *task; |
| 7279 | struct nfs4_get_lease_time_args args; |
| 7280 | struct nfs4_get_lease_time_res res = { |
| 7281 | .lr_fsinfo = fsinfo, |
| 7282 | }; |
| 7283 | struct nfs4_get_lease_time_data data = { |
| 7284 | .args = &args, |
| 7285 | .res = &res, |
| 7286 | .clp = clp, |
| 7287 | }; |
| 7288 | struct rpc_message msg = { |
| 7289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7290 | .rpc_argp = &args, |
| 7291 | .rpc_resp = &res, |
| 7292 | }; |
| 7293 | struct rpc_task_setup task_setup = { |
| 7294 | .rpc_client = clp->cl_rpcclient, |
| 7295 | .rpc_message = &msg, |
| 7296 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7297 | .callback_data = &data, |
| 7298 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7299 | }; |
| 7300 | int status; |
| 7301 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7302 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7303 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7304 | dprintk("--> %s\n", __func__); |
| 7305 | task = rpc_run_task(&task_setup); |
| 7306 | |
| 7307 | if (IS_ERR(task)) |
| 7308 | status = PTR_ERR(task); |
| 7309 | else { |
| 7310 | status = task->tk_status; |
| 7311 | rpc_put_task(task); |
| 7312 | } |
| 7313 | dprintk("<-- %s return %d\n", __func__, status); |
| 7314 | |
| 7315 | return status; |
| 7316 | } |
| 7317 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7318 | /* |
| 7319 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7320 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7321 | * use them. |
| 7322 | * |
| 7323 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7324 | * always set csa_cachethis to FALSE because the current implementation |
| 7325 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7326 | */ |
| 7327 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7328 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7329 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7330 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7331 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7332 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7333 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7334 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7335 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7336 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7337 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7338 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7339 | |
| 7340 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7341 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7342 | __func__, |
| 7343 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7344 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7345 | |
| 7346 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7347 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7348 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7349 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7350 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7351 | args->bc_attrs.max_reqs = 1; |
| 7352 | |
| 7353 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7354 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7355 | __func__, |
| 7356 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7357 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7358 | args->bc_attrs.max_reqs); |
| 7359 | } |
| 7360 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7361 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7362 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7363 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7364 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7365 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7366 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7367 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7368 | return -EINVAL; |
| 7369 | /* |
| 7370 | * Our requested max_ops is the minimum we need; we're not |
| 7371 | * prepared to break up compounds into smaller pieces than that. |
| 7372 | * So, no point even trying to continue if the server won't |
| 7373 | * cooperate: |
| 7374 | */ |
| 7375 | if (rcvd->max_ops < sent->max_ops) |
| 7376 | return -EINVAL; |
| 7377 | if (rcvd->max_reqs == 0) |
| 7378 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7379 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7380 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7381 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7382 | } |
| 7383 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7384 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7385 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7386 | { |
| 7387 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7388 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7389 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7390 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7391 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7392 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7393 | return -EINVAL; |
| 7394 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7395 | return -EINVAL; |
| 7396 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7397 | return -EINVAL; |
| 7398 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7399 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7400 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7401 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7402 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7403 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7404 | return 0; |
| 7405 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7406 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7407 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7408 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7409 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7410 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7411 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7412 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7413 | if (ret) |
| 7414 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7415 | return nfs4_verify_back_channel_attrs(args, res); |
| 7416 | } |
| 7417 | |
| 7418 | static void nfs4_update_session(struct nfs4_session *session, |
| 7419 | struct nfs41_create_session_res *res) |
| 7420 | { |
| 7421 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7422 | /* Mark client id and session as being confirmed */ |
| 7423 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7424 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7425 | session->flags = res->flags; |
| 7426 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7427 | if (res->flags & SESSION4_BACK_CHAN) |
| 7428 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7429 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7430 | } |
| 7431 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7432 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7433 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7434 | { |
| 7435 | struct nfs4_session *session = clp->cl_session; |
| 7436 | struct nfs41_create_session_args args = { |
| 7437 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7438 | .clientid = clp->cl_clientid, |
| 7439 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7440 | .cb_program = NFS4_CALLBACK, |
| 7441 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7442 | struct nfs41_create_session_res res; |
| 7443 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7444 | struct rpc_message msg = { |
| 7445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7446 | .rpc_argp = &args, |
| 7447 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7448 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7449 | }; |
| 7450 | int status; |
| 7451 | |
| 7452 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7453 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7454 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7455 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7456 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7457 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7458 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7459 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7460 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7461 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7462 | if (clp->cl_seqid == res.seqid) |
| 7463 | clp->cl_seqid++; |
| 7464 | if (status) |
| 7465 | goto out; |
| 7466 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7467 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7468 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7469 | return status; |
| 7470 | } |
| 7471 | |
| 7472 | /* |
| 7473 | * Issues a CREATE_SESSION operation to the server. |
| 7474 | * It is the responsibility of the caller to verify the session is |
| 7475 | * expired before calling this routine. |
| 7476 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7477 | 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] | 7478 | { |
| 7479 | int status; |
| 7480 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7481 | struct nfs4_session *session = clp->cl_session; |
| 7482 | |
| 7483 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7484 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7485 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7486 | if (status) |
| 7487 | goto out; |
| 7488 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7489 | /* Init or reset the session slot tables */ |
| 7490 | status = nfs4_setup_session_slot_tables(session); |
| 7491 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7492 | if (status) |
| 7493 | goto out; |
| 7494 | |
| 7495 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7496 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7497 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7498 | out: |
| 7499 | dprintk("<-- %s\n", __func__); |
| 7500 | return status; |
| 7501 | } |
| 7502 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7503 | /* |
| 7504 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7505 | * The caller must serialize access to this routine. |
| 7506 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7507 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7508 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7509 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7510 | struct rpc_message msg = { |
| 7511 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7512 | .rpc_argp = session, |
| 7513 | .rpc_cred = cred, |
| 7514 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7515 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7516 | |
| 7517 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7518 | |
| 7519 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7520 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7521 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7522 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7523 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7524 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7525 | |
| 7526 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7527 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7528 | "Session has been destroyed regardless...\n", status); |
| 7529 | |
| 7530 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7531 | return status; |
| 7532 | } |
| 7533 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7534 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7535 | * Renew the cl_session lease. |
| 7536 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7537 | struct nfs4_sequence_data { |
| 7538 | struct nfs_client *clp; |
| 7539 | struct nfs4_sequence_args args; |
| 7540 | struct nfs4_sequence_res res; |
| 7541 | }; |
| 7542 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7543 | static void nfs41_sequence_release(void *data) |
| 7544 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7545 | struct nfs4_sequence_data *calldata = data; |
| 7546 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7547 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7548 | if (atomic_read(&clp->cl_count) > 1) |
| 7549 | nfs4_schedule_state_renewal(clp); |
| 7550 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7551 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7552 | } |
| 7553 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7554 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7555 | { |
| 7556 | switch(task->tk_status) { |
| 7557 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7558 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7559 | return -EAGAIN; |
| 7560 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7561 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7562 | } |
| 7563 | return 0; |
| 7564 | } |
| 7565 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7566 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7567 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7568 | struct nfs4_sequence_data *calldata = data; |
| 7569 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7570 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7571 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7572 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7573 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7574 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7575 | if (task->tk_status < 0) { |
| 7576 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7577 | if (atomic_read(&clp->cl_count) == 1) |
| 7578 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7579 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7580 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7581 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7582 | return; |
| 7583 | } |
| 7584 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7585 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7586 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7587 | dprintk("<-- %s\n", __func__); |
| 7588 | } |
| 7589 | |
| 7590 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7591 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7592 | struct nfs4_sequence_data *calldata = data; |
| 7593 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7594 | struct nfs4_sequence_args *args; |
| 7595 | struct nfs4_sequence_res *res; |
| 7596 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7597 | args = task->tk_msg.rpc_argp; |
| 7598 | res = task->tk_msg.rpc_resp; |
| 7599 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7600 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7604 | .rpc_call_done = nfs41_sequence_call_done, |
| 7605 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7606 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7607 | }; |
| 7608 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7609 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7610 | struct rpc_cred *cred, |
| 7611 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7612 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7613 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7614 | struct rpc_message msg = { |
| 7615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7616 | .rpc_cred = cred, |
| 7617 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7618 | struct rpc_task_setup task_setup_data = { |
| 7619 | .rpc_client = clp->cl_rpcclient, |
| 7620 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7621 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7622 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7623 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7624 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7625 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7626 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7627 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7628 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7629 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7630 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7631 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7632 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7633 | if (is_privileged) |
| 7634 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7635 | msg.rpc_argp = &calldata->args; |
| 7636 | msg.rpc_resp = &calldata->res; |
| 7637 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7638 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7639 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7640 | return rpc_run_task(&task_setup_data); |
| 7641 | } |
| 7642 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7643 | 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] | 7644 | { |
| 7645 | struct rpc_task *task; |
| 7646 | int ret = 0; |
| 7647 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7648 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7649 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7650 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7651 | if (IS_ERR(task)) |
| 7652 | ret = PTR_ERR(task); |
| 7653 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7654 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7655 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7656 | return ret; |
| 7657 | } |
| 7658 | |
| 7659 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7660 | { |
| 7661 | struct rpc_task *task; |
| 7662 | int ret; |
| 7663 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7664 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7665 | if (IS_ERR(task)) { |
| 7666 | ret = PTR_ERR(task); |
| 7667 | goto out; |
| 7668 | } |
| 7669 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 7670 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7671 | ret = task->tk_status; |
| 7672 | rpc_put_task(task); |
| 7673 | out: |
| 7674 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7675 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7676 | } |
| 7677 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7678 | struct nfs4_reclaim_complete_data { |
| 7679 | struct nfs_client *clp; |
| 7680 | struct nfs41_reclaim_complete_args arg; |
| 7681 | struct nfs41_reclaim_complete_res res; |
| 7682 | }; |
| 7683 | |
| 7684 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7685 | { |
| 7686 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7687 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7688 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7689 | &calldata->arg.seq_args, |
| 7690 | &calldata->res.seq_res, |
| 7691 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7692 | } |
| 7693 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7694 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7695 | { |
| 7696 | switch(task->tk_status) { |
| 7697 | case 0: |
| 7698 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7699 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7700 | break; |
| 7701 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7702 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7703 | /* fall through */ |
| 7704 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7705 | return -EAGAIN; |
| 7706 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7707 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7708 | } |
| 7709 | return 0; |
| 7710 | } |
| 7711 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7712 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7713 | { |
| 7714 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7715 | struct nfs_client *clp = calldata->clp; |
| 7716 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7717 | |
| 7718 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7719 | if (!nfs41_sequence_done(task, res)) |
| 7720 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7721 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7722 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7723 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7724 | rpc_restart_call_prepare(task); |
| 7725 | return; |
| 7726 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7727 | dprintk("<-- %s\n", __func__); |
| 7728 | } |
| 7729 | |
| 7730 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7731 | { |
| 7732 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7733 | |
| 7734 | kfree(calldata); |
| 7735 | } |
| 7736 | |
| 7737 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7738 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7739 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7740 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7741 | }; |
| 7742 | |
| 7743 | /* |
| 7744 | * Issue a global reclaim complete. |
| 7745 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7746 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7747 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7748 | { |
| 7749 | struct nfs4_reclaim_complete_data *calldata; |
| 7750 | struct rpc_task *task; |
| 7751 | struct rpc_message msg = { |
| 7752 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7753 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7754 | }; |
| 7755 | struct rpc_task_setup task_setup_data = { |
| 7756 | .rpc_client = clp->cl_rpcclient, |
| 7757 | .rpc_message = &msg, |
| 7758 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7759 | .flags = RPC_TASK_ASYNC, |
| 7760 | }; |
| 7761 | int status = -ENOMEM; |
| 7762 | |
| 7763 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7764 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7765 | if (calldata == NULL) |
| 7766 | goto out; |
| 7767 | calldata->clp = clp; |
| 7768 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7769 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7770 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7771 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7772 | msg.rpc_argp = &calldata->arg; |
| 7773 | msg.rpc_resp = &calldata->res; |
| 7774 | task_setup_data.callback_data = calldata; |
| 7775 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7776 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7777 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7778 | goto out; |
| 7779 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7780 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7781 | if (status == 0) |
| 7782 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7783 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7784 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7785 | out: |
| 7786 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7787 | return status; |
| 7788 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7789 | |
| 7790 | static void |
| 7791 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7792 | { |
| 7793 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7794 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7795 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7796 | |
| 7797 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7798 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7799 | * right now covering the LAYOUTGET we are about to send. |
| 7800 | * However, that is not so catastrophic, and there seems |
| 7801 | * to be no way to prevent it completely. |
| 7802 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7803 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7804 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7805 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7806 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7807 | NFS_I(lgp->args.inode)->layout, |
Peng Tao | ce6ab4f | 2014-09-06 00:53:24 +0800 | [diff] [blame] | 7808 | &lgp->args.range, |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7809 | lgp->args.ctx->state)) { |
| 7810 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7811 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7815 | { |
| 7816 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7817 | struct inode *inode = lgp->args.inode; |
| 7818 | struct nfs_server *server = NFS_SERVER(inode); |
| 7819 | struct pnfs_layout_hdr *lo; |
| 7820 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7821 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7822 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7823 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7824 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7825 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7826 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7827 | |
| 7828 | switch (task->tk_status) { |
| 7829 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7830 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7831 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7832 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 7833 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 7834 | */ |
| 7835 | case -NFS4ERR_BADLAYOUT: |
| 7836 | goto out_overflow; |
| 7837 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7838 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7839 | * (or clients) writing to the same RAID stripe except when |
| 7840 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7841 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7842 | case -NFS4ERR_LAYOUTTRYLATER: |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7843 | if (lgp->args.minlength == 0) |
| 7844 | goto out_overflow; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7845 | /* |
| 7846 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7847 | * existing layout before getting a new one). |
| 7848 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7849 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7850 | timeo = rpc_get_timeout(task->tk_client); |
| 7851 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7852 | now = jiffies; |
| 7853 | if (time_after(giveup, now)) { |
| 7854 | unsigned long delay; |
| 7855 | |
| 7856 | /* Delay for: |
| 7857 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7858 | * - One last time a jiffie before we give up |
| 7859 | * - exponential backoff (time_now minus start_attempt) |
| 7860 | */ |
| 7861 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7862 | min((giveup - now - 1), |
| 7863 | now - lgp->args.timestamp)); |
| 7864 | |
| 7865 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7866 | __func__, delay); |
| 7867 | rpc_delay(task, delay); |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7868 | /* Do not call nfs4_async_handle_error() */ |
| 7869 | goto out_restart; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7870 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7871 | break; |
| 7872 | case -NFS4ERR_EXPIRED: |
| 7873 | case -NFS4ERR_BAD_STATEID: |
| 7874 | spin_lock(&inode->i_lock); |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7875 | if (nfs4_stateid_match(&lgp->args.stateid, |
| 7876 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7877 | spin_unlock(&inode->i_lock); |
| 7878 | /* If the open stateid was bad, then recover it. */ |
| 7879 | state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7880 | break; |
| 7881 | } |
| 7882 | lo = NFS_I(inode)->layout; |
| 7883 | if (lo && nfs4_stateid_match(&lgp->args.stateid, |
| 7884 | &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7885 | LIST_HEAD(head); |
| 7886 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7887 | /* |
| 7888 | * Mark the bad layout state as invalid, then retry |
| 7889 | * with the current stateid. |
| 7890 | */ |
Kinglong Mee | 8714d46 | 2015-09-20 23:04:22 +0800 | [diff] [blame] | 7891 | set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7892 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7893 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7894 | pnfs_free_lseg_list(&head); |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7895 | } else |
| 7896 | spin_unlock(&inode->i_lock); |
| 7897 | goto out_restart; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7898 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7899 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7900 | goto out_restart; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7901 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7902 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7903 | return; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7904 | out_restart: |
| 7905 | task->tk_status = 0; |
| 7906 | rpc_restart_call_prepare(task); |
| 7907 | return; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7908 | out_overflow: |
| 7909 | task->tk_status = -EOVERFLOW; |
| 7910 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7911 | } |
| 7912 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7913 | static size_t max_response_pages(struct nfs_server *server) |
| 7914 | { |
| 7915 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7916 | return nfs_page_array_len(0, max_resp_sz); |
| 7917 | } |
| 7918 | |
| 7919 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7920 | { |
| 7921 | int i; |
| 7922 | |
| 7923 | if (!pages) |
| 7924 | return; |
| 7925 | |
| 7926 | for (i = 0; i < size; i++) { |
| 7927 | if (!pages[i]) |
| 7928 | break; |
| 7929 | __free_page(pages[i]); |
| 7930 | } |
| 7931 | kfree(pages); |
| 7932 | } |
| 7933 | |
| 7934 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7935 | { |
| 7936 | struct page **pages; |
| 7937 | int i; |
| 7938 | |
| 7939 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7940 | if (!pages) { |
| 7941 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7942 | return NULL; |
| 7943 | } |
| 7944 | |
| 7945 | for (i = 0; i < size; i++) { |
| 7946 | pages[i] = alloc_page(gfp_flags); |
| 7947 | if (!pages[i]) { |
| 7948 | dprintk("%s: failed to allocate page\n", __func__); |
| 7949 | nfs4_free_pages(pages, size); |
| 7950 | return NULL; |
| 7951 | } |
| 7952 | } |
| 7953 | |
| 7954 | return pages; |
| 7955 | } |
| 7956 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7957 | static void nfs4_layoutget_release(void *calldata) |
| 7958 | { |
| 7959 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7960 | struct inode *inode = lgp->args.inode; |
| 7961 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7962 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7963 | |
| 7964 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7965 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7966 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7967 | put_nfs_open_context(lgp->args.ctx); |
| 7968 | kfree(calldata); |
| 7969 | dprintk("<-- %s\n", __func__); |
| 7970 | } |
| 7971 | |
| 7972 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7973 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7974 | .rpc_call_done = nfs4_layoutget_done, |
| 7975 | .rpc_release = nfs4_layoutget_release, |
| 7976 | }; |
| 7977 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7978 | struct pnfs_layout_segment * |
| 7979 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7980 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7981 | struct inode *inode = lgp->args.inode; |
| 7982 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7983 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7984 | struct rpc_task *task; |
| 7985 | struct rpc_message msg = { |
| 7986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7987 | .rpc_argp = &lgp->args, |
| 7988 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7989 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7990 | }; |
| 7991 | struct rpc_task_setup task_setup_data = { |
| 7992 | .rpc_client = server->client, |
| 7993 | .rpc_message = &msg, |
| 7994 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7995 | .callback_data = lgp, |
| 7996 | .flags = RPC_TASK_ASYNC, |
| 7997 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7998 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7999 | int status = 0; |
| 8000 | |
| 8001 | dprintk("--> %s\n", __func__); |
| 8002 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8003 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8004 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8005 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8006 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8007 | if (!lgp->args.layout.pages) { |
| 8008 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8009 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8010 | } |
| 8011 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 8012 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8013 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8014 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8015 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8016 | 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] | 8017 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8018 | task = rpc_run_task(&task_setup_data); |
| 8019 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8020 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8021 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8022 | if (status == 0) |
| 8023 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8024 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8025 | &lgp->args.range, |
| 8026 | &lgp->res.range, |
| 8027 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8028 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8029 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8030 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8031 | rpc_put_task(task); |
| 8032 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8033 | if (status) |
| 8034 | return ERR_PTR(status); |
| 8035 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8036 | } |
| 8037 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8038 | static void |
| 8039 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8040 | { |
| 8041 | struct nfs4_layoutreturn *lrp = calldata; |
| 8042 | |
| 8043 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8044 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8045 | &lrp->args.seq_args, |
| 8046 | &lrp->res.seq_res, |
| 8047 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8048 | } |
| 8049 | |
| 8050 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8051 | { |
| 8052 | struct nfs4_layoutreturn *lrp = calldata; |
| 8053 | struct nfs_server *server; |
| 8054 | |
| 8055 | dprintk("--> %s\n", __func__); |
| 8056 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8057 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8058 | return; |
| 8059 | |
| 8060 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8061 | switch (task->tk_status) { |
| 8062 | default: |
| 8063 | task->tk_status = 0; |
| 8064 | case 0: |
| 8065 | break; |
| 8066 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8067 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8068 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8069 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8070 | return; |
| 8071 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8072 | dprintk("<-- %s\n", __func__); |
| 8073 | } |
| 8074 | |
| 8075 | static void nfs4_layoutreturn_release(void *calldata) |
| 8076 | { |
| 8077 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8078 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8079 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8080 | |
| 8081 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8082 | spin_lock(&lo->plh_inode->i_lock); |
| 8083 | if (lrp->res.lrs_present) |
| 8084 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8085 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, &lrp->args.range); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8086 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8087 | lo->plh_block_lgets--; |
| 8088 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8089 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8090 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8091 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8092 | kfree(calldata); |
| 8093 | dprintk("<-- %s\n", __func__); |
| 8094 | } |
| 8095 | |
| 8096 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8097 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8098 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8099 | .rpc_release = nfs4_layoutreturn_release, |
| 8100 | }; |
| 8101 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8102 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8103 | { |
| 8104 | struct rpc_task *task; |
| 8105 | struct rpc_message msg = { |
| 8106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8107 | .rpc_argp = &lrp->args, |
| 8108 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8109 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8110 | }; |
| 8111 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8112 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8113 | .rpc_message = &msg, |
| 8114 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8115 | .callback_data = lrp, |
| 8116 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8117 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8118 | |
| 8119 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8120 | if (!sync) { |
| 8121 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8122 | if (!lrp->inode) { |
| 8123 | nfs4_layoutreturn_release(lrp); |
| 8124 | return -EAGAIN; |
| 8125 | } |
| 8126 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8127 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8128 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8129 | task = rpc_run_task(&task_setup_data); |
| 8130 | if (IS_ERR(task)) |
| 8131 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8132 | if (sync) |
| 8133 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8134 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8135 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8136 | rpc_put_task(task); |
| 8137 | return status; |
| 8138 | } |
| 8139 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8140 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8141 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8142 | struct pnfs_device *pdev, |
| 8143 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8144 | { |
| 8145 | struct nfs4_getdeviceinfo_args args = { |
| 8146 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8147 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8148 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8149 | }; |
| 8150 | struct nfs4_getdeviceinfo_res res = { |
| 8151 | .pdev = pdev, |
| 8152 | }; |
| 8153 | struct rpc_message msg = { |
| 8154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8155 | .rpc_argp = &args, |
| 8156 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8157 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8158 | }; |
| 8159 | int status; |
| 8160 | |
| 8161 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8162 | 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] | 8163 | if (res.notification & ~args.notify_types) |
| 8164 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8165 | if (res.notification != args.notify_types) |
| 8166 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8167 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8168 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8169 | |
| 8170 | return status; |
| 8171 | } |
| 8172 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8173 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8174 | struct pnfs_device *pdev, |
| 8175 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8176 | { |
| 8177 | struct nfs4_exception exception = { }; |
| 8178 | int err; |
| 8179 | |
| 8180 | do { |
| 8181 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8182 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8183 | &exception); |
| 8184 | } while (exception.retry); |
| 8185 | return err; |
| 8186 | } |
| 8187 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8188 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8189 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8190 | { |
| 8191 | struct nfs4_layoutcommit_data *data = calldata; |
| 8192 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8193 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8194 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8195 | nfs41_setup_sequence(session, |
| 8196 | &data->args.seq_args, |
| 8197 | &data->res.seq_res, |
| 8198 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | static void |
| 8202 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8203 | { |
| 8204 | struct nfs4_layoutcommit_data *data = calldata; |
| 8205 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8206 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8207 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8208 | return; |
| 8209 | |
| 8210 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8211 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8212 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8213 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8214 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8215 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8216 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8217 | break; |
| 8218 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8219 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8220 | rpc_restart_call_prepare(task); |
| 8221 | return; |
| 8222 | } |
| 8223 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8224 | } |
| 8225 | |
| 8226 | static void nfs4_layoutcommit_release(void *calldata) |
| 8227 | { |
| 8228 | struct nfs4_layoutcommit_data *data = calldata; |
| 8229 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8230 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8231 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8232 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8233 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8234 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8235 | kfree(data); |
| 8236 | } |
| 8237 | |
| 8238 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8239 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8240 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8241 | .rpc_release = nfs4_layoutcommit_release, |
| 8242 | }; |
| 8243 | |
| 8244 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8245 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8246 | { |
| 8247 | struct rpc_message msg = { |
| 8248 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8249 | .rpc_argp = &data->args, |
| 8250 | .rpc_resp = &data->res, |
| 8251 | .rpc_cred = data->cred, |
| 8252 | }; |
| 8253 | struct rpc_task_setup task_setup_data = { |
| 8254 | .task = &data->task, |
| 8255 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8256 | .rpc_message = &msg, |
| 8257 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8258 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8259 | }; |
| 8260 | struct rpc_task *task; |
| 8261 | int status = 0; |
| 8262 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8263 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8264 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8265 | data->args.lastbytewritten, |
| 8266 | data->args.inode->i_ino); |
| 8267 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8268 | if (!sync) { |
| 8269 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8270 | if (data->inode == NULL) { |
| 8271 | nfs4_layoutcommit_release(data); |
| 8272 | return -EAGAIN; |
| 8273 | } |
| 8274 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8275 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8276 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8277 | task = rpc_run_task(&task_setup_data); |
| 8278 | if (IS_ERR(task)) |
| 8279 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8280 | if (sync) |
| 8281 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8282 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8283 | dprintk("%s: status %d\n", __func__, status); |
| 8284 | rpc_put_task(task); |
| 8285 | return status; |
| 8286 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8287 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8288 | /** |
| 8289 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8290 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8291 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8292 | static int |
| 8293 | _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] | 8294 | struct nfs_fsinfo *info, |
| 8295 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8296 | { |
| 8297 | struct nfs41_secinfo_no_name_args args = { |
| 8298 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8299 | }; |
| 8300 | struct nfs4_secinfo_res res = { |
| 8301 | .flavors = flavors, |
| 8302 | }; |
| 8303 | struct rpc_message msg = { |
| 8304 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8305 | .rpc_argp = &args, |
| 8306 | .rpc_resp = &res, |
| 8307 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8308 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8309 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8310 | int status; |
| 8311 | |
| 8312 | if (use_integrity) { |
| 8313 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8314 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8315 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | dprintk("--> %s\n", __func__); |
| 8319 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8320 | &res.seq_res, 0); |
| 8321 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8322 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8323 | if (cred) |
| 8324 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8325 | |
| 8326 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8327 | } |
| 8328 | |
| 8329 | static int |
| 8330 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8331 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8332 | { |
| 8333 | struct nfs4_exception exception = { }; |
| 8334 | int err; |
| 8335 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8336 | /* first try using integrity protection */ |
| 8337 | err = -NFS4ERR_WRONGSEC; |
| 8338 | |
| 8339 | /* try to use integrity protection with machine cred */ |
| 8340 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8341 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8342 | flavors, true); |
| 8343 | |
| 8344 | /* |
| 8345 | * if unable to use integrity protection, or SECINFO with |
| 8346 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8347 | * disallowed by spec, but exists in deployed servers) use |
| 8348 | * the current filesystem's rpc_client and the user cred. |
| 8349 | */ |
| 8350 | if (err == -NFS4ERR_WRONGSEC) |
| 8351 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8352 | flavors, false); |
| 8353 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8354 | switch (err) { |
| 8355 | case 0: |
| 8356 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8357 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8358 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8359 | default: |
| 8360 | err = nfs4_handle_exception(server, err, &exception); |
| 8361 | } |
| 8362 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8363 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8364 | return err; |
| 8365 | } |
| 8366 | |
| 8367 | static int |
| 8368 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8369 | struct nfs_fsinfo *info) |
| 8370 | { |
| 8371 | int err; |
| 8372 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8373 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8374 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8375 | struct nfs4_secinfo4 *secinfo; |
| 8376 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8377 | |
| 8378 | page = alloc_page(GFP_KERNEL); |
| 8379 | if (!page) { |
| 8380 | err = -ENOMEM; |
| 8381 | goto out; |
| 8382 | } |
| 8383 | |
| 8384 | flavors = page_address(page); |
| 8385 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8386 | |
| 8387 | /* |
| 8388 | * Fall back on "guess and check" method if |
| 8389 | * the server doesn't support SECINFO_NO_NAME |
| 8390 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8391 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8392 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8393 | goto out_freepage; |
| 8394 | } |
| 8395 | if (err) |
| 8396 | goto out_freepage; |
| 8397 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8398 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8399 | secinfo = &flavors->flavors[i]; |
| 8400 | |
| 8401 | switch (secinfo->flavor) { |
| 8402 | case RPC_AUTH_NULL: |
| 8403 | case RPC_AUTH_UNIX: |
| 8404 | case RPC_AUTH_GSS: |
| 8405 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8406 | &secinfo->flavor_info); |
| 8407 | break; |
| 8408 | default: |
| 8409 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8410 | break; |
| 8411 | } |
| 8412 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8413 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8414 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8415 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8416 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8417 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8418 | info, flavor); |
| 8419 | if (!err) |
| 8420 | break; |
| 8421 | } |
| 8422 | } |
| 8423 | |
| 8424 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8425 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8426 | |
| 8427 | out_freepage: |
| 8428 | put_page(page); |
| 8429 | if (err == -EACCES) |
| 8430 | return -EPERM; |
| 8431 | out: |
| 8432 | return err; |
| 8433 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8434 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8435 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8436 | nfs4_stateid *stateid, |
| 8437 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8438 | { |
| 8439 | int status; |
| 8440 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8441 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8442 | }; |
| 8443 | struct nfs41_test_stateid_res res; |
| 8444 | struct rpc_message msg = { |
| 8445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8446 | .rpc_argp = &args, |
| 8447 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8448 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8449 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8450 | struct rpc_clnt *rpc_client = server->client; |
| 8451 | |
| 8452 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8453 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8454 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8455 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8456 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8457 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8458 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8459 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8460 | if (status != NFS_OK) { |
| 8461 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8462 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8463 | } |
| 8464 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8465 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8466 | } |
| 8467 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8468 | /** |
| 8469 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8470 | * |
| 8471 | * @server: server / transport on which to perform the operation |
| 8472 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8473 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8474 | * |
| 8475 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8476 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8477 | * failed or the state ID is not currently valid. |
| 8478 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8479 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8480 | nfs4_stateid *stateid, |
| 8481 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8482 | { |
| 8483 | struct nfs4_exception exception = { }; |
| 8484 | int err; |
| 8485 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8486 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8487 | if (err != -NFS4ERR_DELAY) |
| 8488 | break; |
| 8489 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8490 | } while (exception.retry); |
| 8491 | return err; |
| 8492 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8493 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8494 | struct nfs_free_stateid_data { |
| 8495 | struct nfs_server *server; |
| 8496 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8497 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8498 | }; |
| 8499 | |
| 8500 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8501 | { |
| 8502 | struct nfs_free_stateid_data *data = calldata; |
| 8503 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8504 | &data->args.seq_args, |
| 8505 | &data->res.seq_res, |
| 8506 | task); |
| 8507 | } |
| 8508 | |
| 8509 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8510 | { |
| 8511 | struct nfs_free_stateid_data *data = calldata; |
| 8512 | |
| 8513 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8514 | |
| 8515 | switch (task->tk_status) { |
| 8516 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8517 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8518 | rpc_restart_call_prepare(task); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | static void nfs41_free_stateid_release(void *calldata) |
| 8523 | { |
| 8524 | kfree(calldata); |
| 8525 | } |
| 8526 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8527 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8528 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8529 | .rpc_call_done = nfs41_free_stateid_done, |
| 8530 | .rpc_release = nfs41_free_stateid_release, |
| 8531 | }; |
| 8532 | |
| 8533 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8534 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8535 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8536 | bool privileged) |
| 8537 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8538 | struct rpc_message msg = { |
| 8539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8540 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8541 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8542 | struct rpc_task_setup task_setup = { |
| 8543 | .rpc_client = server->client, |
| 8544 | .rpc_message = &msg, |
| 8545 | .callback_ops = &nfs41_free_stateid_ops, |
| 8546 | .flags = RPC_TASK_ASYNC, |
| 8547 | }; |
| 8548 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8549 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8550 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8551 | &task_setup.rpc_client, &msg); |
| 8552 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8553 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8554 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8555 | if (!data) |
| 8556 | return ERR_PTR(-ENOMEM); |
| 8557 | data->server = server; |
| 8558 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8559 | |
| 8560 | task_setup.callback_data = data; |
| 8561 | |
| 8562 | msg.rpc_argp = &data->args; |
| 8563 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8564 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8565 | if (privileged) |
| 8566 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8567 | |
| 8568 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8569 | } |
| 8570 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8571 | /** |
| 8572 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8573 | * |
| 8574 | * @server: server / transport on which to perform the operation |
| 8575 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8576 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8577 | * |
| 8578 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8579 | * negative NFS4ERR value is returned. |
| 8580 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8581 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8582 | nfs4_stateid *stateid, |
| 8583 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8584 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8585 | struct rpc_task *task; |
| 8586 | int ret; |
| 8587 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8588 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8589 | if (IS_ERR(task)) |
| 8590 | return PTR_ERR(task); |
| 8591 | ret = rpc_wait_for_completion_task(task); |
| 8592 | if (!ret) |
| 8593 | ret = task->tk_status; |
| 8594 | rpc_put_task(task); |
| 8595 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8596 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8597 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8598 | static void |
| 8599 | 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] | 8600 | { |
| 8601 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8602 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8603 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8604 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8605 | nfs4_free_lock_state(server, lsp); |
| 8606 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8607 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8608 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8609 | } |
| 8610 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8611 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8612 | const nfs4_stateid *s2) |
| 8613 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8614 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8615 | return false; |
| 8616 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8617 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8618 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8619 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8620 | return true; |
| 8621 | |
| 8622 | return false; |
| 8623 | } |
| 8624 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8625 | #endif /* CONFIG_NFS_V4_1 */ |
| 8626 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8627 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8628 | const nfs4_stateid *s2) |
| 8629 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8630 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8631 | } |
| 8632 | |
| 8633 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8634 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8635 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8636 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8637 | .recover_open = nfs4_open_reclaim, |
| 8638 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8639 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8640 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8641 | }; |
| 8642 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8643 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8644 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8645 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8646 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8647 | .recover_open = nfs4_open_reclaim, |
| 8648 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8649 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8650 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8651 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8652 | }; |
| 8653 | #endif /* CONFIG_NFS_V4_1 */ |
| 8654 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8655 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8656 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8657 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8658 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8659 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8660 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8661 | }; |
| 8662 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8663 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8664 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8665 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8666 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8667 | .recover_open = nfs41_open_expired, |
| 8668 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8669 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8670 | }; |
| 8671 | #endif /* CONFIG_NFS_V4_1 */ |
| 8672 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8673 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8674 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8675 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8676 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8677 | }; |
| 8678 | |
| 8679 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8680 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8681 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8682 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8683 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8684 | }; |
| 8685 | #endif |
| 8686 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8687 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8688 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8689 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8690 | }; |
| 8691 | |
| 8692 | #if defined(CONFIG_NFS_V4_1) |
| 8693 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8694 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8695 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8696 | }; |
| 8697 | #endif /* CONFIG_NFS_V4_1 */ |
| 8698 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8699 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8700 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8701 | .init_caps = NFS_CAP_READDIRPLUS |
| 8702 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8703 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8704 | .init_client = nfs40_init_client, |
| 8705 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8706 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8707 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8708 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8709 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8710 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8711 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8712 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8713 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8714 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8715 | }; |
| 8716 | |
| 8717 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8718 | static struct nfs_seqid * |
| 8719 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 8720 | { |
| 8721 | return NULL; |
| 8722 | } |
| 8723 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8724 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8725 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8726 | .init_caps = NFS_CAP_READDIRPLUS |
| 8727 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8728 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8729 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8730 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8731 | .init_client = nfs41_init_client, |
| 8732 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8733 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8734 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8735 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8736 | .alloc_seqid = nfs_alloc_no_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8737 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8738 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8739 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8740 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8741 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8742 | }; |
| 8743 | #endif |
| 8744 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8745 | #if defined(CONFIG_NFS_V4_2) |
| 8746 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8747 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8748 | .init_caps = NFS_CAP_READDIRPLUS |
| 8749 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8750 | | NFS_CAP_POSIX_LOCK |
| 8751 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8752 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8753 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8754 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 8755 | | NFS_CAP_SEEK |
| 8756 | | NFS_CAP_LAYOUTSTATS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8757 | .init_client = nfs41_init_client, |
| 8758 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8759 | .match_stateid = nfs41_match_stateid, |
| 8760 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8761 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8762 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8763 | .alloc_seqid = nfs_alloc_no_seqid, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8764 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8765 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8766 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 8767 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8768 | }; |
| 8769 | #endif |
| 8770 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8771 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8772 | [0] = &nfs_v4_0_minor_ops, |
| 8773 | #if defined(CONFIG_NFS_V4_1) |
| 8774 | [1] = &nfs_v4_1_minor_ops, |
| 8775 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8776 | #if defined(CONFIG_NFS_V4_2) |
| 8777 | [2] = &nfs_v4_2_minor_ops, |
| 8778 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8779 | }; |
| 8780 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8781 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8782 | .create = nfs_create, |
| 8783 | .lookup = nfs_lookup, |
| 8784 | .atomic_open = nfs_atomic_open, |
| 8785 | .link = nfs_link, |
| 8786 | .unlink = nfs_unlink, |
| 8787 | .symlink = nfs_symlink, |
| 8788 | .mkdir = nfs_mkdir, |
| 8789 | .rmdir = nfs_rmdir, |
| 8790 | .mknod = nfs_mknod, |
| 8791 | .rename = nfs_rename, |
| 8792 | .permission = nfs_permission, |
| 8793 | .getattr = nfs_getattr, |
| 8794 | .setattr = nfs_setattr, |
| 8795 | .getxattr = generic_getxattr, |
| 8796 | .setxattr = generic_setxattr, |
| 8797 | .listxattr = generic_listxattr, |
| 8798 | .removexattr = generic_removexattr, |
| 8799 | }; |
| 8800 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8801 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8802 | .permission = nfs_permission, |
| 8803 | .getattr = nfs_getattr, |
| 8804 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8805 | .getxattr = generic_getxattr, |
| 8806 | .setxattr = generic_setxattr, |
| 8807 | .listxattr = generic_listxattr, |
| 8808 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8809 | }; |
| 8810 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8811 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8812 | .version = 4, /* protocol version */ |
| 8813 | .dentry_ops = &nfs4_dentry_operations, |
| 8814 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8815 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8816 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8817 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8818 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8819 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8820 | .getattr = nfs4_proc_getattr, |
| 8821 | .setattr = nfs4_proc_setattr, |
| 8822 | .lookup = nfs4_proc_lookup, |
| 8823 | .access = nfs4_proc_access, |
| 8824 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8825 | .create = nfs4_proc_create, |
| 8826 | .remove = nfs4_proc_remove, |
| 8827 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8828 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8829 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8830 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8831 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8832 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8833 | .link = nfs4_proc_link, |
| 8834 | .symlink = nfs4_proc_symlink, |
| 8835 | .mkdir = nfs4_proc_mkdir, |
| 8836 | .rmdir = nfs4_proc_remove, |
| 8837 | .readdir = nfs4_proc_readdir, |
| 8838 | .mknod = nfs4_proc_mknod, |
| 8839 | .statfs = nfs4_proc_statfs, |
| 8840 | .fsinfo = nfs4_proc_fsinfo, |
| 8841 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8842 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8843 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8844 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8845 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8846 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8847 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8848 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8849 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8850 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8851 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8852 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8853 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8854 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8855 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8856 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8857 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8858 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8859 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8860 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8861 | .create_server = nfs4_create_server, |
| 8862 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8863 | }; |
| 8864 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8865 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8866 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8867 | .list = nfs4_xattr_list_nfs4_acl, |
| 8868 | .get = nfs4_xattr_get_nfs4_acl, |
| 8869 | .set = nfs4_xattr_set_nfs4_acl, |
| 8870 | }; |
| 8871 | |
| 8872 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8873 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8874 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8875 | &nfs4_xattr_nfs4_label_handler, |
| 8876 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8877 | NULL |
| 8878 | }; |
| 8879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8880 | /* |
| 8881 | * Local variables: |
| 8882 | * c-basic-offset: 8 |
| 8883 | * End: |
| 8884 | */ |