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> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.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" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 83 | 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] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 87 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 90 | struct rpc_cred *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 92 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 96 | static inline struct nfs4_label * |
| 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 98 | struct iattr *sattr, struct nfs4_label *label) |
| 99 | { |
| 100 | int err; |
| 101 | |
| 102 | if (label == NULL) |
| 103 | return NULL; |
| 104 | |
| 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 106 | return NULL; |
| 107 | |
| 108 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) |
| 109 | return NULL; |
| 110 | |
| 111 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 112 | &dentry->d_name, (void **)&label->label, &label->len); |
| 113 | if (err == 0) |
| 114 | return label; |
| 115 | |
| 116 | return NULL; |
| 117 | } |
| 118 | static inline void |
| 119 | nfs4_label_release_security(struct nfs4_label *label) |
| 120 | { |
| 121 | if (label) |
| 122 | security_release_secctx(label->label, label->len); |
| 123 | } |
| 124 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 125 | { |
| 126 | if (label) |
| 127 | return server->attr_bitmask; |
| 128 | |
| 129 | return server->attr_bitmask_nl; |
| 130 | } |
| 131 | #else |
| 132 | static inline struct nfs4_label * |
| 133 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 134 | struct iattr *sattr, struct nfs4_label *l) |
| 135 | { return NULL; } |
| 136 | static inline void |
| 137 | nfs4_label_release_security(struct nfs4_label *label) |
| 138 | { return; } |
| 139 | static inline u32 * |
| 140 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 141 | { return server->attr_bitmask; } |
| 142 | #endif |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 145 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 147 | if (err >= -1000) |
| 148 | return err; |
| 149 | switch (err) { |
| 150 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 151 | case -NFS4ERR_LAYOUTTRYLATER: |
| 152 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 153 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 155 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 156 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 157 | case -NFS4ERR_BADOWNER: |
| 158 | case -NFS4ERR_BADNAME: |
| 159 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 160 | case -NFS4ERR_SHARE_DENIED: |
| 161 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 162 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 163 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 164 | case -NFS4ERR_ACCESS: |
| 165 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 166 | case -NFS4ERR_FILE_OPEN: |
| 167 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 170 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 171 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* |
| 177 | * This is our standard bitmap for GETATTR requests. |
| 178 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 179 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | FATTR4_WORD0_TYPE |
| 181 | | FATTR4_WORD0_CHANGE |
| 182 | | FATTR4_WORD0_SIZE |
| 183 | | FATTR4_WORD0_FSID |
| 184 | | FATTR4_WORD0_FILEID, |
| 185 | FATTR4_WORD1_MODE |
| 186 | | FATTR4_WORD1_NUMLINKS |
| 187 | | FATTR4_WORD1_OWNER |
| 188 | | FATTR4_WORD1_OWNER_GROUP |
| 189 | | FATTR4_WORD1_RAWDEV |
| 190 | | FATTR4_WORD1_SPACE_USED |
| 191 | | FATTR4_WORD1_TIME_ACCESS |
| 192 | | FATTR4_WORD1_TIME_METADATA |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 193 | | FATTR4_WORD1_TIME_MODIFY, |
| 194 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 195 | FATTR4_WORD2_SECURITY_LABEL |
| 196 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 199 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 200 | FATTR4_WORD0_TYPE |
| 201 | | FATTR4_WORD0_CHANGE |
| 202 | | FATTR4_WORD0_SIZE |
| 203 | | FATTR4_WORD0_FSID |
| 204 | | FATTR4_WORD0_FILEID, |
| 205 | FATTR4_WORD1_MODE |
| 206 | | FATTR4_WORD1_NUMLINKS |
| 207 | | FATTR4_WORD1_OWNER |
| 208 | | FATTR4_WORD1_OWNER_GROUP |
| 209 | | FATTR4_WORD1_RAWDEV |
| 210 | | FATTR4_WORD1_SPACE_USED |
| 211 | | FATTR4_WORD1_TIME_ACCESS |
| 212 | | FATTR4_WORD1_TIME_METADATA |
| 213 | | FATTR4_WORD1_TIME_MODIFY, |
| 214 | FATTR4_WORD2_MDSTHRESHOLD |
| 215 | }; |
| 216 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 217 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 218 | FATTR4_WORD0_TYPE |
| 219 | | FATTR4_WORD0_CHANGE |
| 220 | | FATTR4_WORD0_FILEID, |
| 221 | }; |
| 222 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 223 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | FATTR4_WORD0_FILES_AVAIL |
| 225 | | FATTR4_WORD0_FILES_FREE |
| 226 | | FATTR4_WORD0_FILES_TOTAL, |
| 227 | FATTR4_WORD1_SPACE_AVAIL |
| 228 | | FATTR4_WORD1_SPACE_FREE |
| 229 | | FATTR4_WORD1_SPACE_TOTAL |
| 230 | }; |
| 231 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 232 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | FATTR4_WORD0_MAXLINK |
| 234 | | FATTR4_WORD0_MAXNAME, |
| 235 | 0 |
| 236 | }; |
| 237 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 238 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | | FATTR4_WORD0_MAXREAD |
| 240 | | FATTR4_WORD0_MAXWRITE |
| 241 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 242 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 243 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 244 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 247 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 248 | FATTR4_WORD0_TYPE |
| 249 | | FATTR4_WORD0_CHANGE |
| 250 | | FATTR4_WORD0_SIZE |
| 251 | | FATTR4_WORD0_FSID |
| 252 | | FATTR4_WORD0_FILEID |
| 253 | | FATTR4_WORD0_FS_LOCATIONS, |
| 254 | FATTR4_WORD1_MODE |
| 255 | | FATTR4_WORD1_NUMLINKS |
| 256 | | FATTR4_WORD1_OWNER |
| 257 | | FATTR4_WORD1_OWNER_GROUP |
| 258 | | FATTR4_WORD1_RAWDEV |
| 259 | | FATTR4_WORD1_SPACE_USED |
| 260 | | FATTR4_WORD1_TIME_ACCESS |
| 261 | | FATTR4_WORD1_TIME_METADATA |
| 262 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 263 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 264 | }; |
| 265 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 266 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | struct nfs4_readdir_arg *readdir) |
| 268 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 269 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 272 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | readdir->cookie = 0; |
| 278 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 279 | if (cookie == 2) |
| 280 | return; |
| 281 | |
| 282 | /* |
| 283 | * NFSv4 servers do not return entries for '.' and '..' |
| 284 | * Therefore, we fake these entries here. We let '.' |
| 285 | * have cookie 0 and '..' have cookie 1. Note that |
| 286 | * when talking to the server, we always send cookie 0 |
| 287 | * instead of 1 or 2. |
| 288 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 289 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | if (cookie == 0) { |
| 292 | *p++ = xdr_one; /* next */ |
| 293 | *p++ = xdr_zero; /* cookie, first word */ |
| 294 | *p++ = xdr_one; /* cookie, second word */ |
| 295 | *p++ = xdr_one; /* entry len */ |
| 296 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 297 | p++; |
| 298 | *p++ = xdr_one; /* bitmap length */ |
| 299 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 300 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 301 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | *p++ = xdr_one; /* next */ |
| 305 | *p++ = xdr_zero; /* cookie, first word */ |
| 306 | *p++ = xdr_two; /* cookie, second word */ |
| 307 | *p++ = xdr_two; /* entry len */ |
| 308 | memcpy(p, "..\0\0", 4); /* entry */ |
| 309 | p++; |
| 310 | *p++ = xdr_one; /* bitmap length */ |
| 311 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 312 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 313 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | readdir->pgbase = (char *)p - (char *)start; |
| 316 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 317 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 321 | { |
| 322 | int res = 0; |
| 323 | |
| 324 | might_sleep(); |
| 325 | |
| 326 | if (*timeout <= 0) |
| 327 | *timeout = NFS4_POLL_RETRY_MIN; |
| 328 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 329 | *timeout = NFS4_POLL_RETRY_MAX; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 330 | freezable_schedule_timeout_killable_unsafe(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 331 | if (fatal_signal_pending(current)) |
| 332 | res = -ERESTARTSYS; |
| 333 | *timeout <<= 1; |
| 334 | return res; |
| 335 | } |
| 336 | |
| 337 | /* This is the error handling routine for processes that are allowed |
| 338 | * to sleep. |
| 339 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 340 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | { |
| 342 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 343 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 344 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | int ret = errorcode; |
| 346 | |
| 347 | exception->retry = 0; |
| 348 | switch(errorcode) { |
| 349 | case 0: |
| 350 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 351 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 352 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 353 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 354 | exception->retry = 1; |
| 355 | return 0; |
| 356 | } |
| 357 | if (state == NULL) |
| 358 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 359 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 360 | if (ret < 0) |
| 361 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 362 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 363 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 364 | case -NFS4ERR_ADMIN_REVOKED: |
| 365 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 366 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 367 | nfs_remove_bad_delegation(inode); |
| 368 | exception->retry = 1; |
| 369 | break; |
| 370 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 371 | if (state == NULL) |
| 372 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 373 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 374 | if (ret < 0) |
| 375 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 376 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 378 | if (state != NULL) { |
| 379 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 380 | if (ret < 0) |
| 381 | break; |
| 382 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 384 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 385 | nfs4_schedule_lease_recovery(clp); |
| 386 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 387 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 388 | case -NFS4ERR_BADSESSION: |
| 389 | case -NFS4ERR_BADSLOT: |
| 390 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 391 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 392 | case -NFS4ERR_DEADSESSION: |
| 393 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 394 | case -NFS4ERR_SEQ_MISORDERED: |
| 395 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 396 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 397 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 398 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 399 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 400 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 401 | if (exception->timeout > HZ) { |
| 402 | /* We have retried a decent amount, time to |
| 403 | * fail |
| 404 | */ |
| 405 | ret = -EBUSY; |
| 406 | break; |
| 407 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 408 | case -NFS4ERR_GRACE: |
| 409 | case -NFS4ERR_DELAY: |
| 410 | ret = nfs4_delay(server->client, &exception->timeout); |
| 411 | if (ret != 0) |
| 412 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 413 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 414 | case -NFS4ERR_OLD_STATEID: |
| 415 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 416 | break; |
| 417 | case -NFS4ERR_BADOWNER: |
| 418 | /* The following works around a Linux server bug! */ |
| 419 | case -NFS4ERR_BADNAME: |
| 420 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 421 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 422 | exception->retry = 1; |
| 423 | printk(KERN_WARNING "NFS: v4 server %s " |
| 424 | "does not accept raw " |
| 425 | "uid/gids. " |
| 426 | "Reenabling the idmapper.\n", |
| 427 | server->nfs_client->cl_hostname); |
| 428 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | } |
| 430 | /* We failed to handle the error */ |
| 431 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 432 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 433 | ret = nfs4_wait_clnt_recover(clp); |
| 434 | if (ret == 0) |
| 435 | exception->retry = 1; |
| 436 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 439 | /* |
| 440 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 441 | * or 'false' otherwise. |
| 442 | */ |
| 443 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 444 | { |
| 445 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 446 | |
| 447 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 448 | flavor == RPC_AUTH_GSS_KRB5P) |
| 449 | return true; |
| 450 | |
| 451 | return false; |
| 452 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 453 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 454 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | spin_lock(&clp->cl_lock); |
| 457 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 458 | clp->cl_last_renewal = timestamp; |
| 459 | spin_unlock(&clp->cl_lock); |
| 460 | } |
| 461 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 463 | { |
| 464 | do_renew_lease(server->nfs_client, timestamp); |
| 465 | } |
| 466 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 467 | struct nfs4_call_sync_data { |
| 468 | const struct nfs_server *seq_server; |
| 469 | struct nfs4_sequence_args *seq_args; |
| 470 | struct nfs4_sequence_res *seq_res; |
| 471 | }; |
| 472 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 473 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 474 | struct nfs4_sequence_res *res, int cache_reply) |
| 475 | { |
| 476 | args->sa_slot = NULL; |
| 477 | args->sa_cache_this = cache_reply; |
| 478 | args->sa_privileged = 0; |
| 479 | |
| 480 | res->sr_slot = NULL; |
| 481 | } |
| 482 | |
| 483 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 484 | { |
| 485 | args->sa_privileged = 1; |
| 486 | } |
| 487 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 488 | static int nfs40_setup_sequence(const struct nfs_server *server, |
| 489 | struct nfs4_sequence_args *args, |
| 490 | struct nfs4_sequence_res *res, |
| 491 | struct rpc_task *task) |
| 492 | { |
| 493 | struct nfs4_slot_table *tbl = server->nfs_client->cl_slot_tbl; |
| 494 | struct nfs4_slot *slot; |
| 495 | |
| 496 | /* slot already allocated? */ |
| 497 | if (res->sr_slot != NULL) |
| 498 | goto out_start; |
| 499 | |
| 500 | spin_lock(&tbl->slot_tbl_lock); |
| 501 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 502 | goto out_sleep; |
| 503 | |
| 504 | slot = nfs4_alloc_slot(tbl); |
| 505 | if (IS_ERR(slot)) { |
| 506 | if (slot == ERR_PTR(-ENOMEM)) |
| 507 | task->tk_timeout = HZ >> 2; |
| 508 | goto out_sleep; |
| 509 | } |
| 510 | spin_unlock(&tbl->slot_tbl_lock); |
| 511 | |
| 512 | args->sa_slot = slot; |
| 513 | res->sr_slot = slot; |
| 514 | |
| 515 | out_start: |
| 516 | rpc_call_start(task); |
| 517 | return 0; |
| 518 | |
| 519 | out_sleep: |
| 520 | if (args->sa_privileged) |
| 521 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 522 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 523 | else |
| 524 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 525 | spin_unlock(&tbl->slot_tbl_lock); |
| 526 | return -EAGAIN; |
| 527 | } |
| 528 | |
| 529 | static int nfs40_sequence_done(struct rpc_task *task, |
| 530 | struct nfs4_sequence_res *res) |
| 531 | { |
| 532 | struct nfs4_slot *slot = res->sr_slot; |
| 533 | struct nfs4_slot_table *tbl; |
| 534 | |
| 535 | if (!RPC_WAS_SENT(task)) |
| 536 | goto out; |
| 537 | |
| 538 | tbl = slot->table; |
| 539 | spin_lock(&tbl->slot_tbl_lock); |
| 540 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 541 | nfs4_free_slot(tbl, slot); |
| 542 | spin_unlock(&tbl->slot_tbl_lock); |
| 543 | |
| 544 | res->sr_slot = NULL; |
| 545 | out: |
| 546 | return 1; |
| 547 | } |
| 548 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 549 | #if defined(CONFIG_NFS_V4_1) |
| 550 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 551 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 552 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 553 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 554 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 555 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 556 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 557 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 558 | /* just wake up the next guy waiting since |
| 559 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 560 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 561 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 562 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 563 | tbl = res->sr_slot->table; |
| 564 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 565 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 566 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 567 | /* Be nice to the server: try to ensure that the last transmitted |
| 568 | * value for highest_user_slotid <= target_highest_slotid |
| 569 | */ |
| 570 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 571 | send_new_highest_used_slotid = true; |
| 572 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 573 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 574 | send_new_highest_used_slotid = false; |
| 575 | goto out_unlock; |
| 576 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 577 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 578 | |
| 579 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 580 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 581 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 582 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 583 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 584 | if (send_new_highest_used_slotid) |
| 585 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 588 | static 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] | 589 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 590 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 591 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 592 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 593 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 594 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 595 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 596 | /* don't increment the sequence number if the task wasn't sent */ |
| 597 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 598 | goto out; |
| 599 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 600 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 601 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 602 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 603 | if (slot->interrupted) { |
| 604 | slot->interrupted = 0; |
| 605 | interrupted = true; |
| 606 | } |
| 607 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 608 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 609 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 610 | switch (res->sr_status) { |
| 611 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 612 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 613 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 614 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 615 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 616 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 617 | if (res->sr_status_flags != 0) |
| 618 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 619 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 620 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 621 | case 1: |
| 622 | /* |
| 623 | * sr_status remains 1 if an RPC level error occurred. |
| 624 | * The server may or may not have processed the sequence |
| 625 | * operation.. |
| 626 | * Mark the slot as having hosted an interrupted RPC call. |
| 627 | */ |
| 628 | slot->interrupted = 1; |
| 629 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 630 | case -NFS4ERR_DELAY: |
| 631 | /* The server detected a resend of the RPC call and |
| 632 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 633 | * of RFC5661. |
| 634 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 635 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 636 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 637 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 638 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 639 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 640 | case -NFS4ERR_BADSLOT: |
| 641 | /* |
| 642 | * The slot id we used was probably retired. Try again |
| 643 | * using a different slot id. |
| 644 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 645 | goto retry_nowait; |
| 646 | case -NFS4ERR_SEQ_MISORDERED: |
| 647 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 648 | * Was the last operation on this sequence interrupted? |
| 649 | * If so, retry after bumping the sequence number. |
| 650 | */ |
| 651 | if (interrupted) { |
| 652 | ++slot->seq_nr; |
| 653 | goto retry_nowait; |
| 654 | } |
| 655 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 656 | * Could this slot have been previously retired? |
| 657 | * If so, then the server may be expecting seq_nr = 1! |
| 658 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 659 | if (slot->seq_nr != 1) { |
| 660 | slot->seq_nr = 1; |
| 661 | goto retry_nowait; |
| 662 | } |
| 663 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 664 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 665 | ++slot->seq_nr; |
| 666 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 667 | default: |
| 668 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 669 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 670 | } |
| 671 | out: |
| 672 | /* The session may be reset by one of the error handlers. */ |
| 673 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 674 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 675 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 676 | retry_nowait: |
| 677 | if (rpc_restart_call_prepare(task)) { |
| 678 | task->tk_status = 0; |
| 679 | ret = 0; |
| 680 | } |
| 681 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 682 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 683 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 684 | goto out; |
| 685 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 686 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 687 | } |
| 688 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | static int nfs4_sequence_done(struct rpc_task *task, |
| 690 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 691 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 692 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 693 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 694 | if (!res->sr_slot->table->session) |
| 695 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 696 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 699 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 700 | struct nfs4_sequence_args *args, |
| 701 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 702 | struct rpc_task *task) |
| 703 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 704 | struct nfs4_slot *slot; |
| 705 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 706 | |
| 707 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 708 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 709 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 710 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 711 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 712 | tbl = &session->fc_slot_table; |
| 713 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 714 | task->tk_timeout = 0; |
| 715 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 716 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 717 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 718 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 719 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 720 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 721 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 724 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 725 | if (IS_ERR(slot)) { |
| 726 | /* If out of memory, try again in 1/4 second */ |
| 727 | if (slot == ERR_PTR(-ENOMEM)) |
| 728 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 729 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 730 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 731 | } |
| 732 | spin_unlock(&tbl->slot_tbl_lock); |
| 733 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 734 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 735 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 736 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 737 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 738 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 739 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 740 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 741 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 742 | /* |
| 743 | * sr_status is only set in decode_sequence, and so will remain |
| 744 | * set to 1 if an rpc level failure occurs. |
| 745 | */ |
| 746 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 747 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 748 | out_success: |
| 749 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 750 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 751 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 752 | /* Privileged tasks are queued with top priority */ |
| 753 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 754 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 755 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 756 | else |
| 757 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 758 | spin_unlock(&tbl->slot_tbl_lock); |
| 759 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 760 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 761 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 762 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 763 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 764 | struct nfs4_sequence_args *args, |
| 765 | struct nfs4_sequence_res *res, |
| 766 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 767 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 768 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 769 | int ret = 0; |
| 770 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 771 | if (!session) |
| 772 | return nfs40_setup_sequence(server, args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 773 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 774 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 775 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 776 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 777 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 778 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 779 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 780 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 781 | return ret; |
| 782 | } |
| 783 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 784 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 785 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 786 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 787 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 788 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 789 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 790 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 791 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 794 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 795 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 796 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 797 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 801 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 802 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 803 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 804 | }; |
| 805 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 806 | #else /* !CONFIG_NFS_V4_1 */ |
| 807 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 808 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 809 | struct nfs4_sequence_args *args, |
| 810 | struct nfs4_sequence_res *res, |
| 811 | struct rpc_task *task) |
| 812 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 813 | return nfs40_setup_sequence(server, args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 814 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_done(struct rpc_task *task, |
| 817 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 818 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 819 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 820 | } |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 821 | |
| 822 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 823 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 824 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 825 | { |
| 826 | struct nfs4_call_sync_data *data = calldata; |
| 827 | nfs4_setup_sequence(data->seq_server, |
| 828 | data->seq_args, data->seq_res, task); |
| 829 | } |
| 830 | |
| 831 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 832 | { |
| 833 | struct nfs4_call_sync_data *data = calldata; |
| 834 | nfs4_sequence_done(task, data->seq_res); |
| 835 | } |
| 836 | |
| 837 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 838 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 839 | .rpc_call_done = nfs40_call_sync_done, |
| 840 | }; |
| 841 | |
| 842 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 843 | struct nfs_server *server, |
| 844 | struct rpc_message *msg, |
| 845 | struct nfs4_sequence_args *args, |
| 846 | struct nfs4_sequence_res *res) |
| 847 | { |
| 848 | int ret; |
| 849 | struct rpc_task *task; |
| 850 | struct nfs_client *clp = server->nfs_client; |
| 851 | struct nfs4_call_sync_data data = { |
| 852 | .seq_server = server, |
| 853 | .seq_args = args, |
| 854 | .seq_res = res, |
| 855 | }; |
| 856 | struct rpc_task_setup task_setup = { |
| 857 | .rpc_client = clnt, |
| 858 | .rpc_message = msg, |
| 859 | .callback_ops = clp->cl_mvops->call_sync_ops, |
| 860 | .callback_data = &data |
| 861 | }; |
| 862 | |
| 863 | task = rpc_run_task(&task_setup); |
| 864 | if (IS_ERR(task)) |
| 865 | ret = PTR_ERR(task); |
| 866 | else { |
| 867 | ret = task->tk_status; |
| 868 | rpc_put_task(task); |
| 869 | } |
| 870 | return ret; |
| 871 | } |
| 872 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 873 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 874 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 875 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 876 | struct rpc_message *msg, |
| 877 | struct nfs4_sequence_args *args, |
| 878 | struct nfs4_sequence_res *res, |
| 879 | int cache_reply) |
| 880 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 881 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 882 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 883 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 884 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 885 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 887 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 889 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 890 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 891 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 892 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 893 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 894 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 895 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 898 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 899 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 900 | struct nfs_openargs o_arg; |
| 901 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 902 | struct nfs_open_confirmargs c_arg; |
| 903 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 904 | struct nfs4_string owner_name; |
| 905 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 906 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 907 | struct nfs4_label *f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 908 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 909 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 910 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 911 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 912 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 913 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 914 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 915 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 916 | int rpc_status; |
| 917 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 918 | }; |
| 919 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 920 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 921 | int err, struct nfs4_exception *exception) |
| 922 | { |
| 923 | if (err != -EINVAL) |
| 924 | return false; |
| 925 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 926 | return false; |
| 927 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 928 | exception->retry = 1; |
| 929 | return true; |
| 930 | } |
| 931 | |
| 932 | static enum open_claim_type4 |
| 933 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 934 | enum open_claim_type4 claim) |
| 935 | { |
| 936 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 937 | return claim; |
| 938 | switch (claim) { |
| 939 | default: |
| 940 | return claim; |
| 941 | case NFS4_OPEN_CLAIM_FH: |
| 942 | return NFS4_OPEN_CLAIM_NULL; |
| 943 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 944 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 945 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 946 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 947 | } |
| 948 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 949 | |
| 950 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 951 | { |
| 952 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 953 | p->o_res.f_label = p->f_label; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 954 | p->o_res.seqid = p->o_arg.seqid; |
| 955 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 956 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 957 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 958 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 959 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 962 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 964 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 965 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 966 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 967 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 968 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 969 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 970 | struct inode *dir = parent->d_inode; |
| 971 | struct nfs_server *server = NFS_SERVER(dir); |
| 972 | struct nfs4_opendata *p; |
| 973 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 974 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 975 | if (p == NULL) |
| 976 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 977 | |
| 978 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 979 | if (IS_ERR(p->f_label)) |
| 980 | goto err_free_p; |
| 981 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 982 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 983 | if (p->o_arg.seqid == NULL) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 984 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 985 | nfs_sb_active(dentry->d_sb); |
| 986 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 987 | p->dir = parent; |
| 988 | p->owner = sp; |
| 989 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | p->o_arg.open_flags = flags; |
| 991 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 992 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 993 | * will return permission denied for all bits until close */ |
| 994 | if (!(flags & O_EXCL)) { |
| 995 | /* ask server to check for all possible rights as results |
| 996 | * are cached */ |
| 997 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 998 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 999 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1000 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1001 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1002 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1003 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1004 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1005 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1006 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1007 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1008 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1009 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1010 | case NFS4_OPEN_CLAIM_NULL: |
| 1011 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1012 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1013 | p->o_arg.fh = NFS_FH(dir); |
| 1014 | break; |
| 1015 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1016 | case NFS4_OPEN_CLAIM_FH: |
| 1017 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1018 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1019 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 1020 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1021 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1022 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1023 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1024 | p->o_arg.u.attrs = &p->attrs; |
| 1025 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1026 | |
| 1027 | verf[0] = jiffies; |
| 1028 | verf[1] = current->pid; |
| 1029 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1030 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1031 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1032 | p->c_arg.fh = &p->o_res.fh; |
| 1033 | p->c_arg.stateid = &p->o_res.stateid; |
| 1034 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1035 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1036 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1037 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1038 | |
| 1039 | err_free_label: |
| 1040 | nfs4_label_free(p->f_label); |
| 1041 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1042 | kfree(p); |
| 1043 | err: |
| 1044 | dput(parent); |
| 1045 | return NULL; |
| 1046 | } |
| 1047 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1048 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1049 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1050 | struct nfs4_opendata *p = container_of(kref, |
| 1051 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1052 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1053 | |
| 1054 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | if (p->state != NULL) |
| 1056 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1057 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1058 | |
| 1059 | nfs4_label_free(p->f_label); |
| 1060 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1061 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1062 | dput(p->dentry); |
| 1063 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1064 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1065 | kfree(p); |
| 1066 | } |
| 1067 | |
| 1068 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1069 | { |
| 1070 | if (p != NULL) |
| 1071 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1074 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1075 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1076 | int ret; |
| 1077 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1078 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1079 | return ret; |
| 1080 | } |
| 1081 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1082 | 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] | 1083 | { |
| 1084 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1086 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1087 | goto out; |
| 1088 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1089 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1090 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1091 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1092 | break; |
| 1093 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1094 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1095 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1096 | break; |
| 1097 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1098 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1099 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1100 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1101 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1102 | return ret; |
| 1103 | } |
| 1104 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1106 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1107 | if (delegation == NULL) |
| 1108 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1109 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1110 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1111 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1112 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1113 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1114 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1115 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1116 | return 1; |
| 1117 | } |
| 1118 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1119 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1120 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1122 | case FMODE_WRITE: |
| 1123 | state->n_wronly++; |
| 1124 | break; |
| 1125 | case FMODE_READ: |
| 1126 | state->n_rdonly++; |
| 1127 | break; |
| 1128 | case FMODE_READ|FMODE_WRITE: |
| 1129 | state->n_rdwr++; |
| 1130 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1131 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1134 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1135 | { |
| 1136 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1137 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1138 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1139 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1141 | case FMODE_READ: |
| 1142 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1143 | break; |
| 1144 | case FMODE_WRITE: |
| 1145 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1146 | break; |
| 1147 | case FMODE_READ|FMODE_WRITE: |
| 1148 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1149 | } |
| 1150 | } |
| 1151 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1152 | static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1153 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1154 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1156 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1159 | 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] | 1160 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1161 | /* |
| 1162 | * Protect the call to nfs4_state_set_mode_locked and |
| 1163 | * serialise the stateid update |
| 1164 | */ |
| 1165 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1166 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1167 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1168 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1169 | } |
| 1170 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1171 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1172 | write_sequnlock(&state->seqlock); |
| 1173 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1174 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1175 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1178 | 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] | 1179 | { |
| 1180 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1181 | struct nfs_delegation *deleg_cur; |
| 1182 | int ret = 0; |
| 1183 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1184 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1185 | |
| 1186 | rcu_read_lock(); |
| 1187 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1188 | if (deleg_cur == NULL) |
| 1189 | goto no_delegation; |
| 1190 | |
| 1191 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1192 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1193 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1194 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1195 | goto no_delegation_unlock; |
| 1196 | |
| 1197 | if (delegation == NULL) |
| 1198 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1199 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1200 | goto no_delegation_unlock; |
| 1201 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1202 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1203 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1204 | ret = 1; |
| 1205 | no_delegation_unlock: |
| 1206 | spin_unlock(&deleg_cur->lock); |
| 1207 | no_delegation: |
| 1208 | rcu_read_unlock(); |
| 1209 | |
| 1210 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1211 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1212 | ret = 1; |
| 1213 | } |
| 1214 | |
| 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1219 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1220 | { |
| 1221 | struct nfs_delegation *delegation; |
| 1222 | |
| 1223 | rcu_read_lock(); |
| 1224 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1225 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1226 | rcu_read_unlock(); |
| 1227 | return; |
| 1228 | } |
| 1229 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1230 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1233 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1234 | { |
| 1235 | struct nfs4_state *state = opendata->state; |
| 1236 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1237 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1238 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1239 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1240 | nfs4_stateid stateid; |
| 1241 | int ret = -EAGAIN; |
| 1242 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1243 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1244 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1245 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1246 | if (can_open_cached(state, fmode, open_mode)) { |
| 1247 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1248 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1249 | goto out_return_state; |
| 1250 | } |
| 1251 | spin_unlock(&state->owner->so_lock); |
| 1252 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1253 | rcu_read_lock(); |
| 1254 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1255 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1256 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1257 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1258 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1259 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1260 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1261 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1262 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1263 | if (!opendata->is_recover) { |
| 1264 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1265 | if (ret != 0) |
| 1266 | goto out; |
| 1267 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1268 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1269 | |
| 1270 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1271 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1272 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1273 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1274 | out: |
| 1275 | return ERR_PTR(ret); |
| 1276 | out_return_state: |
| 1277 | atomic_inc(&state->count); |
| 1278 | return state; |
| 1279 | } |
| 1280 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1281 | static void |
| 1282 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1283 | { |
| 1284 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1285 | struct nfs_delegation *delegation; |
| 1286 | int delegation_flags = 0; |
| 1287 | |
| 1288 | rcu_read_lock(); |
| 1289 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1290 | if (delegation) |
| 1291 | delegation_flags = delegation->flags; |
| 1292 | rcu_read_unlock(); |
| 1293 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1294 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1295 | "returning a delegation for " |
| 1296 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1297 | clp->cl_hostname); |
| 1298 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1299 | nfs_inode_set_delegation(state->inode, |
| 1300 | data->owner->so_cred, |
| 1301 | &data->o_res); |
| 1302 | else |
| 1303 | nfs_inode_reclaim_delegation(state->inode, |
| 1304 | data->owner->so_cred, |
| 1305 | &data->o_res); |
| 1306 | } |
| 1307 | |
| 1308 | /* |
| 1309 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1310 | * and update the nfs4_state. |
| 1311 | */ |
| 1312 | static struct nfs4_state * |
| 1313 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1314 | { |
| 1315 | struct inode *inode = data->state->inode; |
| 1316 | struct nfs4_state *state = data->state; |
| 1317 | int ret; |
| 1318 | |
| 1319 | if (!data->rpc_done) { |
| 1320 | ret = data->rpc_status; |
| 1321 | goto err; |
| 1322 | } |
| 1323 | |
| 1324 | ret = -ESTALE; |
| 1325 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1326 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1327 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1328 | goto err; |
| 1329 | |
| 1330 | ret = -ENOMEM; |
| 1331 | state = nfs4_get_open_state(inode, data->owner); |
| 1332 | if (state == NULL) |
| 1333 | goto err; |
| 1334 | |
| 1335 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1336 | if (ret) |
| 1337 | goto err; |
| 1338 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1339 | nfs_setsecurity(inode, &data->f_attr, data->f_label); |
| 1340 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1341 | if (data->o_res.delegation_type != 0) |
| 1342 | nfs4_opendata_check_deleg(data, state); |
| 1343 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1344 | data->o_arg.fmode); |
| 1345 | |
| 1346 | return state; |
| 1347 | err: |
| 1348 | return ERR_PTR(ret); |
| 1349 | |
| 1350 | } |
| 1351 | |
| 1352 | static struct nfs4_state * |
| 1353 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1354 | { |
| 1355 | struct inode *inode; |
| 1356 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1357 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1358 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1359 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1360 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1361 | goto out; |
| 1362 | } |
| 1363 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1364 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1365 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1366 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1367 | 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] | 1368 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1369 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1370 | goto err; |
| 1371 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1372 | state = nfs4_get_open_state(inode, data->owner); |
| 1373 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1374 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1375 | if (data->o_res.delegation_type != 0) |
| 1376 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1377 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1378 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1379 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1380 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1381 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1382 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1383 | err_put_inode: |
| 1384 | iput(inode); |
| 1385 | err: |
| 1386 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1387 | } |
| 1388 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1389 | static struct nfs4_state * |
| 1390 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1391 | { |
| 1392 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1393 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1394 | return _nfs4_opendata_to_nfs4_state(data); |
| 1395 | } |
| 1396 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1397 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1398 | { |
| 1399 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1400 | struct nfs_open_context *ctx; |
| 1401 | |
| 1402 | spin_lock(&state->inode->i_lock); |
| 1403 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1404 | if (ctx->state != state) |
| 1405 | continue; |
| 1406 | get_nfs_open_context(ctx); |
| 1407 | spin_unlock(&state->inode->i_lock); |
| 1408 | return ctx; |
| 1409 | } |
| 1410 | spin_unlock(&state->inode->i_lock); |
| 1411 | return ERR_PTR(-ENOENT); |
| 1412 | } |
| 1413 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1414 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1415 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1416 | { |
| 1417 | struct nfs4_opendata *opendata; |
| 1418 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1419 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1420 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1421 | if (opendata == NULL) |
| 1422 | return ERR_PTR(-ENOMEM); |
| 1423 | opendata->state = state; |
| 1424 | atomic_inc(&state->count); |
| 1425 | return opendata; |
| 1426 | } |
| 1427 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1428 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1429 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1430 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1431 | int ret; |
| 1432 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1433 | opendata->o_arg.open_flags = 0; |
| 1434 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1435 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1436 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1437 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1438 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1439 | if (ret != 0) |
| 1440 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1441 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1442 | if (IS_ERR(newstate)) |
| 1443 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1444 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1445 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1450 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1451 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1452 | int ret; |
| 1453 | |
| 1454 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1455 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1456 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1457 | smp_rmb(); |
| 1458 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1459 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1460 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1461 | if (ret != 0) |
| 1462 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1463 | if (newstate != state) |
| 1464 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1465 | } |
| 1466 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1467 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1468 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1469 | if (ret != 0) |
| 1470 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1471 | if (newstate != state) |
| 1472 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1473 | } |
| 1474 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1475 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1476 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1477 | if (ret != 0) |
| 1478 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1479 | if (newstate != state) |
| 1480 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1481 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1482 | /* |
| 1483 | * We may have performed cached opens for all three recoveries. |
| 1484 | * Check if we need to update the current stateid. |
| 1485 | */ |
| 1486 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1487 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1488 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1489 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1490 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1491 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1492 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1493 | return 0; |
| 1494 | } |
| 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | /* |
| 1497 | * OPEN_RECLAIM: |
| 1498 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1500 | 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] | 1501 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1502 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1503 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1504 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | int status; |
| 1506 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1507 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1508 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1509 | if (IS_ERR(opendata)) |
| 1510 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1511 | rcu_read_lock(); |
| 1512 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1513 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1514 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1515 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1516 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1517 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1518 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | return status; |
| 1520 | } |
| 1521 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1522 | 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] | 1523 | { |
| 1524 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1525 | struct nfs4_exception exception = { }; |
| 1526 | int err; |
| 1527 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1528 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1529 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1530 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1531 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1532 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } while (exception.retry); |
| 1536 | return err; |
| 1537 | } |
| 1538 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1539 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1540 | { |
| 1541 | struct nfs_open_context *ctx; |
| 1542 | int ret; |
| 1543 | |
| 1544 | ctx = nfs4_state_find_open_context(state); |
| 1545 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1546 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1547 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1548 | put_nfs_open_context(ctx); |
| 1549 | return ret; |
| 1550 | } |
| 1551 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1552 | 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] | 1553 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1554 | switch (err) { |
| 1555 | default: |
| 1556 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1557 | "%d.\n", __func__, err); |
| 1558 | case 0: |
| 1559 | case -ENOENT: |
| 1560 | case -ESTALE: |
| 1561 | break; |
| 1562 | case -NFS4ERR_BADSESSION: |
| 1563 | case -NFS4ERR_BADSLOT: |
| 1564 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1565 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1566 | case -NFS4ERR_DEADSESSION: |
| 1567 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1568 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1569 | return -EAGAIN; |
| 1570 | case -NFS4ERR_STALE_CLIENTID: |
| 1571 | case -NFS4ERR_STALE_STATEID: |
| 1572 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1573 | case -NFS4ERR_EXPIRED: |
| 1574 | /* Don't recall a delegation if it was lost */ |
| 1575 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1576 | return -EAGAIN; |
| 1577 | case -NFS4ERR_DELEG_REVOKED: |
| 1578 | case -NFS4ERR_ADMIN_REVOKED: |
| 1579 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1580 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1581 | nfs_inode_find_state_and_recover(state->inode, |
| 1582 | stateid); |
| 1583 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1584 | return 0; |
| 1585 | case -NFS4ERR_DELAY: |
| 1586 | case -NFS4ERR_GRACE: |
| 1587 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1588 | ssleep(1); |
| 1589 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1590 | case -ENOMEM: |
| 1591 | case -NFS4ERR_DENIED: |
| 1592 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1593 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | return err; |
| 1596 | } |
| 1597 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1598 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1599 | { |
| 1600 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1601 | struct nfs4_opendata *opendata; |
| 1602 | int err; |
| 1603 | |
| 1604 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1605 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1606 | if (IS_ERR(opendata)) |
| 1607 | return PTR_ERR(opendata); |
| 1608 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1609 | err = nfs4_open_recover(opendata, state); |
| 1610 | nfs4_opendata_put(opendata); |
| 1611 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1612 | } |
| 1613 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1614 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1615 | { |
| 1616 | struct nfs4_opendata *data = calldata; |
| 1617 | |
| 1618 | nfs40_setup_sequence(data->o_arg.server, &data->o_arg.seq_args, |
| 1619 | &data->o_res.seq_res, task); |
| 1620 | } |
| 1621 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1622 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1623 | { |
| 1624 | struct nfs4_opendata *data = calldata; |
| 1625 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1626 | nfs40_sequence_done(task, &data->o_res.seq_res); |
| 1627 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1628 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1629 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1630 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1631 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1632 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1633 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1634 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | static void nfs4_open_confirm_release(void *calldata) |
| 1638 | { |
| 1639 | struct nfs4_opendata *data = calldata; |
| 1640 | struct nfs4_state *state = NULL; |
| 1641 | |
| 1642 | /* If this request hasn't been cancelled, do nothing */ |
| 1643 | if (data->cancelled == 0) |
| 1644 | goto out_free; |
| 1645 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1646 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1647 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1648 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1649 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1650 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1651 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1652 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1656 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1657 | .rpc_call_done = nfs4_open_confirm_done, |
| 1658 | .rpc_release = nfs4_open_confirm_release, |
| 1659 | }; |
| 1660 | |
| 1661 | /* |
| 1662 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1663 | */ |
| 1664 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1665 | { |
| 1666 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1667 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1668 | struct rpc_message msg = { |
| 1669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1670 | .rpc_argp = &data->c_arg, |
| 1671 | .rpc_resp = &data->c_res, |
| 1672 | .rpc_cred = data->owner->so_cred, |
| 1673 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1674 | struct rpc_task_setup task_setup_data = { |
| 1675 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1676 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1677 | .callback_ops = &nfs4_open_confirm_ops, |
| 1678 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1679 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1680 | .flags = RPC_TASK_ASYNC, |
| 1681 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | int status; |
| 1683 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1684 | nfs4_init_sequence(&data->o_arg.seq_args, &data->o_res.seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1685 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1686 | data->rpc_done = 0; |
| 1687 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1688 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1689 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1690 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1691 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1692 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1693 | if (status != 0) { |
| 1694 | data->cancelled = 1; |
| 1695 | smp_wmb(); |
| 1696 | } else |
| 1697 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1698 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | return status; |
| 1700 | } |
| 1701 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1702 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1704 | struct nfs4_opendata *data = calldata; |
| 1705 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1706 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1707 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1709 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1710 | /* |
| 1711 | * Check if we still need to send an OPEN call, or if we can use |
| 1712 | * a delegation instead. |
| 1713 | */ |
| 1714 | if (data->state != NULL) { |
| 1715 | struct nfs_delegation *delegation; |
| 1716 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1717 | 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] | 1718 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | rcu_read_lock(); |
| 1720 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1721 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1722 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1723 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1724 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1725 | rcu_read_unlock(); |
| 1726 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1727 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1728 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1729 | switch (data->o_arg.claim) { |
| 1730 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1731 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1732 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1733 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1734 | case NFS4_OPEN_CLAIM_FH: |
| 1735 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1736 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1737 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1738 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1739 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1740 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1741 | &data->o_res.seq_res, |
| 1742 | task) != 0) |
| 1743 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1744 | |
| 1745 | /* Set the create mode (note dependency on the session type) */ |
| 1746 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1747 | if (data->o_arg.open_flags & O_EXCL) { |
| 1748 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1749 | if (nfs4_has_persistent_session(clp)) |
| 1750 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1751 | else if (clp->cl_mvops->minor_version > 0) |
| 1752 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1753 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1754 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1755 | unlock_no_action: |
| 1756 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1757 | out_no_action: |
| 1758 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1759 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1760 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1761 | } |
| 1762 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1763 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1764 | { |
| 1765 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1767 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1768 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1769 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1770 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1771 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1772 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1773 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1774 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1775 | case S_IFREG: |
| 1776 | break; |
| 1777 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1778 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1779 | break; |
| 1780 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1781 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1782 | break; |
| 1783 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1784 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1785 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1786 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1787 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1788 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1789 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1790 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1791 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1792 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1793 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1794 | static void nfs4_open_release(void *calldata) |
| 1795 | { |
| 1796 | struct nfs4_opendata *data = calldata; |
| 1797 | struct nfs4_state *state = NULL; |
| 1798 | |
| 1799 | /* If this request hasn't been cancelled, do nothing */ |
| 1800 | if (data->cancelled == 0) |
| 1801 | goto out_free; |
| 1802 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1803 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1804 | goto out_free; |
| 1805 | /* In case we need an open_confirm, no cleanup! */ |
| 1806 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1807 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1808 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1809 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1810 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1811 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1812 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1816 | .rpc_call_prepare = nfs4_open_prepare, |
| 1817 | .rpc_call_done = nfs4_open_done, |
| 1818 | .rpc_release = nfs4_open_release, |
| 1819 | }; |
| 1820 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1821 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1822 | { |
| 1823 | struct inode *dir = data->dir->d_inode; |
| 1824 | struct nfs_server *server = NFS_SERVER(dir); |
| 1825 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1826 | struct nfs_openres *o_res = &data->o_res; |
| 1827 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1828 | struct rpc_message msg = { |
| 1829 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1830 | .rpc_argp = o_arg, |
| 1831 | .rpc_resp = o_res, |
| 1832 | .rpc_cred = data->owner->so_cred, |
| 1833 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1834 | struct rpc_task_setup task_setup_data = { |
| 1835 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1836 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1837 | .callback_ops = &nfs4_open_ops, |
| 1838 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1839 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1840 | .flags = RPC_TASK_ASYNC, |
| 1841 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1842 | int status; |
| 1843 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1844 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1845 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1846 | data->rpc_done = 0; |
| 1847 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1848 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1849 | data->is_recover = 0; |
| 1850 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1851 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1852 | data->is_recover = 1; |
| 1853 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1854 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1855 | if (IS_ERR(task)) |
| 1856 | return PTR_ERR(task); |
| 1857 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1858 | if (status != 0) { |
| 1859 | data->cancelled = 1; |
| 1860 | smp_wmb(); |
| 1861 | } else |
| 1862 | status = data->rpc_status; |
| 1863 | rpc_put_task(task); |
| 1864 | |
| 1865 | return status; |
| 1866 | } |
| 1867 | |
| 1868 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1869 | { |
| 1870 | struct inode *dir = data->dir->d_inode; |
| 1871 | struct nfs_openres *o_res = &data->o_res; |
| 1872 | int status; |
| 1873 | |
| 1874 | status = nfs4_run_open_task(data, 1); |
| 1875 | if (status != 0 || !data->rpc_done) |
| 1876 | return status; |
| 1877 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1878 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1879 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1880 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1881 | status = _nfs4_proc_open_confirm(data); |
| 1882 | if (status != 0) |
| 1883 | return status; |
| 1884 | } |
| 1885 | |
| 1886 | return status; |
| 1887 | } |
| 1888 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1889 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1890 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1891 | struct nfs4_state *state, fmode_t fmode, |
| 1892 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1893 | { |
| 1894 | struct nfs_access_entry cache; |
| 1895 | u32 mask; |
| 1896 | |
| 1897 | /* access call failed or for some reason the server doesn't |
| 1898 | * support any access modes -- defer access call until later */ |
| 1899 | if (opendata->o_res.access_supported == 0) |
| 1900 | return 0; |
| 1901 | |
| 1902 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1903 | /* don't check MAY_WRITE - a newly created file may not have |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1904 | * write mode bits, but POSIX allows the creating process to write. |
| 1905 | * use openflags to check for exec, because fmode won't |
| 1906 | * always have FMODE_EXEC set when file open for exec. */ |
| 1907 | if (openflags & __FMODE_EXEC) { |
| 1908 | /* ONLY check for exec rights */ |
| 1909 | mask = MAY_EXEC; |
| 1910 | } else if (fmode & FMODE_READ) |
| 1911 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1912 | |
| 1913 | cache.cred = cred; |
| 1914 | cache.jiffies = jiffies; |
| 1915 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1916 | nfs_access_add_cache(state->inode, &cache); |
| 1917 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1918 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1919 | return 0; |
| 1920 | |
| 1921 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1922 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1923 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1924 | } |
| 1925 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1926 | /* |
| 1927 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1928 | */ |
| 1929 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1930 | { |
| 1931 | struct inode *dir = data->dir->d_inode; |
| 1932 | struct nfs_server *server = NFS_SERVER(dir); |
| 1933 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1934 | struct nfs_openres *o_res = &data->o_res; |
| 1935 | int status; |
| 1936 | |
| 1937 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1938 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1939 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1940 | if (status != 0) { |
| 1941 | if (status == -NFS4ERR_BADNAME && |
| 1942 | !(o_arg->open_flags & O_CREAT)) |
| 1943 | return -ENOENT; |
| 1944 | return status; |
| 1945 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1946 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1947 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1948 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1949 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1950 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1951 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1952 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1954 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1956 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } |
| 1958 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1959 | _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] | 1960 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1963 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1964 | { |
| 1965 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1966 | } |
| 1967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | /* |
| 1969 | * OPEN_EXPIRED: |
| 1970 | * reclaim state on the server after a network partition. |
| 1971 | * Assumes caller holds the appropriate lock |
| 1972 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1973 | 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] | 1974 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1975 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1976 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1978 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1979 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1980 | if (IS_ERR(opendata)) |
| 1981 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1982 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1983 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1984 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1985 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1986 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1989 | 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] | 1990 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1991 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1992 | struct nfs4_exception exception = { }; |
| 1993 | int err; |
| 1994 | |
| 1995 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1996 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1997 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1998 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1999 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2000 | switch (err) { |
| 2001 | default: |
| 2002 | goto out; |
| 2003 | case -NFS4ERR_GRACE: |
| 2004 | case -NFS4ERR_DELAY: |
| 2005 | nfs4_handle_exception(server, err, &exception); |
| 2006 | err = 0; |
| 2007 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2008 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2009 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2010 | return err; |
| 2011 | } |
| 2012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2014 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2016 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2018 | ctx = nfs4_state_find_open_context(state); |
| 2019 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2020 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2021 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2022 | put_nfs_open_context(ctx); |
| 2023 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2026 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2027 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2028 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2029 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2030 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2031 | struct nfs_delegation *delegation; |
| 2032 | struct rpc_cred *cred = NULL; |
| 2033 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2034 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2035 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2036 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 2037 | return; |
| 2038 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2039 | /* Get the delegation credential for use by test/free_stateid */ |
| 2040 | rcu_read_lock(); |
| 2041 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 2042 | if (delegation != NULL && |
| 2043 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 2044 | cred = get_rpccred(delegation->cred); |
| 2045 | rcu_read_unlock(); |
| 2046 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2047 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2048 | } else |
| 2049 | rcu_read_unlock(); |
| 2050 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2051 | if (status != NFS_OK) { |
| 2052 | /* Free the stateid unless the server explicitly |
| 2053 | * informs us the stateid is unrecognized. */ |
| 2054 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2055 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2056 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2057 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2058 | write_seqlock(&state->seqlock); |
| 2059 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2060 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2061 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2062 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2063 | |
| 2064 | if (cred != NULL) |
| 2065 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2070 | * |
| 2071 | * @state: NFSv4 state for an inode |
| 2072 | * |
| 2073 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2074 | * Otherwise a negative NFS4ERR value is returned. |
| 2075 | */ |
| 2076 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2077 | { |
| 2078 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2079 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2080 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2081 | int status; |
| 2082 | |
| 2083 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2084 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2085 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2086 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2087 | return -NFS4ERR_BAD_STATEID; |
| 2088 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2089 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2090 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2091 | if (status != NFS_OK) { |
| 2092 | /* Free the stateid unless the server explicitly |
| 2093 | * informs us the stateid is unrecognized. */ |
| 2094 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2095 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2096 | |
| 2097 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2098 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2099 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2100 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2101 | } |
| 2102 | return status; |
| 2103 | } |
| 2104 | |
| 2105 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2106 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2107 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2108 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2109 | nfs41_clear_delegation_stateid(state); |
| 2110 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2111 | if (status != NFS_OK) |
| 2112 | status = nfs4_open_expired(sp, state); |
| 2113 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2114 | } |
| 2115 | #endif |
| 2116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2118 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2119 | * fields corresponding to attributes that were used to store the verifier. |
| 2120 | * Make sure we clobber those fields in the later setattr call |
| 2121 | */ |
| 2122 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2123 | { |
| 2124 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2125 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2126 | sattr->ia_valid |= ATTR_ATIME; |
| 2127 | |
| 2128 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2129 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2130 | sattr->ia_valid |= ATTR_MTIME; |
| 2131 | } |
| 2132 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2133 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2134 | fmode_t fmode, |
| 2135 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2136 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2137 | { |
| 2138 | struct nfs4_state_owner *sp = opendata->owner; |
| 2139 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2140 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2141 | struct nfs4_state *state; |
| 2142 | unsigned int seq; |
| 2143 | int ret; |
| 2144 | |
| 2145 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2146 | |
| 2147 | ret = _nfs4_proc_open(opendata); |
| 2148 | if (ret != 0) |
| 2149 | goto out; |
| 2150 | |
| 2151 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2152 | ret = PTR_ERR(state); |
| 2153 | if (IS_ERR(state)) |
| 2154 | goto out; |
| 2155 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2156 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2157 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2158 | dentry = opendata->dentry; |
| 2159 | if (dentry->d_inode == NULL) { |
| 2160 | /* FIXME: Is this d_drop() ever needed? */ |
| 2161 | d_drop(dentry); |
| 2162 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2163 | if (dentry == NULL) { |
| 2164 | dentry = opendata->dentry; |
| 2165 | } else if (dentry != ctx->dentry) { |
| 2166 | dput(ctx->dentry); |
| 2167 | ctx->dentry = dget(dentry); |
| 2168 | } |
| 2169 | nfs_set_verifier(dentry, |
| 2170 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 2171 | } |
| 2172 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2173 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2174 | if (ret != 0) |
| 2175 | goto out; |
| 2176 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2177 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2178 | if (dentry->d_inode == state->inode) { |
| 2179 | nfs_inode_attach_open_context(ctx); |
| 2180 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2181 | nfs4_schedule_stateid_recovery(server, state); |
| 2182 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2183 | out: |
| 2184 | return ret; |
| 2185 | } |
| 2186 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2187 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2188 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2190 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2191 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2192 | int flags, |
| 2193 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2194 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | { |
| 2196 | struct nfs4_state_owner *sp; |
| 2197 | struct nfs4_state *state = NULL; |
| 2198 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2199 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2200 | struct dentry *dentry = ctx->dentry; |
| 2201 | struct rpc_cred *cred = ctx->cred; |
| 2202 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2203 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2204 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2205 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2206 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
| 2208 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2210 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2211 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2213 | goto out_err; |
| 2214 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2215 | status = nfs4_recover_expired_lease(server); |
| 2216 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2217 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2218 | if (dentry->d_inode != NULL) |
| 2219 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2220 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2221 | if (dentry->d_inode) |
| 2222 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2223 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2224 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2225 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2226 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2228 | if (label) { |
| 2229 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2230 | if (IS_ERR(olabel)) { |
| 2231 | status = PTR_ERR(olabel); |
| 2232 | goto err_opendata_put; |
| 2233 | } |
| 2234 | } |
| 2235 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2236 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2237 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2238 | if (!opendata->f_attr.mdsthreshold) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2239 | goto err_free_label; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2240 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2241 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2242 | if (dentry->d_inode != NULL) |
| 2243 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2244 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2245 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2246 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2247 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2248 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2249 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2250 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2251 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2252 | nfs4_exclusive_attrset(opendata, sattr); |
| 2253 | |
| 2254 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2255 | status = nfs4_do_setattr(state->inode, cred, |
| 2256 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2257 | state, label, olabel); |
| 2258 | if (status == 0) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2259 | nfs_setattr_update_inode(state->inode, sattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2260 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2261 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2262 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2263 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2264 | |
| 2265 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2266 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2267 | else |
| 2268 | kfree(opendata->f_attr.mdsthreshold); |
| 2269 | opendata->f_attr.mdsthreshold = NULL; |
| 2270 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2271 | nfs4_label_free(olabel); |
| 2272 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2273 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2276 | err_free_label: |
| 2277 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2278 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2279 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2280 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2281 | err_put_state_owner: |
| 2282 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | return status; |
| 2285 | } |
| 2286 | |
| 2287 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2288 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2289 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2290 | int flags, |
| 2291 | struct iattr *sattr, |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2292 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2294 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | struct nfs4_exception exception = { }; |
| 2296 | struct nfs4_state *res; |
| 2297 | int status; |
| 2298 | |
| 2299 | do { |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2300 | status = _nfs4_do_open(dir, ctx, flags, sattr, label); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2301 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2302 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | if (status == 0) |
| 2304 | break; |
| 2305 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2306 | * book-keeping w.r.t. state-changing operations |
| 2307 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2308 | * It is actually a sign of a bug on the client or on the server. |
| 2309 | * |
| 2310 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2311 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | * have unhashed the old state_owner for us, and that we can |
| 2313 | * therefore safely retry using a new one. We should still warn |
| 2314 | * the user though... |
| 2315 | */ |
| 2316 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2317 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2318 | " returned a bad sequence-id error!\n", |
| 2319 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | exception.retry = 1; |
| 2321 | continue; |
| 2322 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2323 | /* |
| 2324 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2325 | * state before it received the OPEN_CONFIRM. |
| 2326 | * Recover by retrying the request as per the discussion |
| 2327 | * on Page 181 of RFC3530. |
| 2328 | */ |
| 2329 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2330 | exception.retry = 1; |
| 2331 | continue; |
| 2332 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2333 | if (status == -EAGAIN) { |
| 2334 | /* We must have found a delegation */ |
| 2335 | exception.retry = 1; |
| 2336 | continue; |
| 2337 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2338 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2339 | continue; |
| 2340 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | status, &exception)); |
| 2342 | } while (exception.retry); |
| 2343 | return res; |
| 2344 | } |
| 2345 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2346 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2347 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2348 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2349 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2351 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2353 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | .iap = sattr, |
| 2355 | .server = server, |
| 2356 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2357 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | }; |
| 2359 | struct nfs_setattrres res = { |
| 2360 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2361 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | .server = server, |
| 2363 | }; |
| 2364 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2366 | .rpc_argp = &arg, |
| 2367 | .rpc_resp = &res, |
| 2368 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2370 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2371 | fmode_t fmode; |
| 2372 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2373 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2375 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2376 | if (ilabel) |
| 2377 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2378 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2379 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2381 | /* Servers should only apply open mode checks for file size changes */ |
| 2382 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2383 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2384 | |
| 2385 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2386 | /* Use that stateid */ |
| 2387 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2388 | struct nfs_lockowner lockowner = { |
| 2389 | .l_owner = current->files, |
| 2390 | .l_pid = current->tgid, |
| 2391 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2392 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2393 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2394 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2395 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2397 | 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] | 2398 | if (status == 0 && state != NULL) |
| 2399 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2400 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2403 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2404 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2405 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2406 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2408 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2409 | struct nfs4_exception exception = { |
| 2410 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2411 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2412 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | int err; |
| 2414 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2415 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2416 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2417 | switch (err) { |
| 2418 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2419 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2420 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2421 | "applying open mode checks to " |
| 2422 | "a SETATTR that is not " |
| 2423 | "changing file size.\n", |
| 2424 | server->nfs_client->cl_hostname); |
| 2425 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2426 | if (state && !(state->state & FMODE_WRITE)) { |
| 2427 | err = -EBADF; |
| 2428 | if (sattr->ia_valid & ATTR_OPEN) |
| 2429 | err = -EACCES; |
| 2430 | goto out; |
| 2431 | } |
| 2432 | } |
| 2433 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2435 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | return err; |
| 2437 | } |
| 2438 | |
| 2439 | struct nfs4_closedata { |
| 2440 | struct inode *inode; |
| 2441 | struct nfs4_state *state; |
| 2442 | struct nfs_closeargs arg; |
| 2443 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2444 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2445 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2446 | bool roc; |
| 2447 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | }; |
| 2449 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2450 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2451 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2452 | struct nfs4_closedata *calldata = data; |
| 2453 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2454 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2455 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2456 | if (calldata->roc) |
| 2457 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2458 | nfs4_put_open_state(calldata->state); |
| 2459 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2460 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2461 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2462 | kfree(calldata); |
| 2463 | } |
| 2464 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2465 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2466 | fmode_t fmode) |
| 2467 | { |
| 2468 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2469 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2470 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2471 | case FMODE_WRITE: |
| 2472 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2473 | break; |
| 2474 | case FMODE_READ: |
| 2475 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2476 | break; |
| 2477 | case 0: |
| 2478 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2479 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2480 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2481 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2482 | spin_unlock(&state->owner->so_lock); |
| 2483 | } |
| 2484 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2485 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2487 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2490 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2491 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2492 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2493 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2494 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | /* hmm. we are done with the inode, and in the process of freeing |
| 2496 | * the state_owner. we keep this around to process errors |
| 2497 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | switch (task->tk_status) { |
| 2499 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2500 | if (calldata->roc) |
| 2501 | pnfs_roc_set_barrier(state->inode, |
| 2502 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2503 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2504 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2505 | nfs4_close_clear_stateid_flags(state, |
| 2506 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | break; |
| 2508 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2509 | case -NFS4ERR_OLD_STATEID: |
| 2510 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2512 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2513 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2515 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2516 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2518 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2519 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2520 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2523 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2525 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2526 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2527 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2528 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2529 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2530 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2531 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2532 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2533 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2534 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2535 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2536 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2537 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2538 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2539 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2540 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2541 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2542 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2543 | } |
| 2544 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2545 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2546 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2547 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2548 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2549 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2550 | if (!nfs4_valid_open_stateid(state)) |
| 2551 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2552 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2553 | |
| 2554 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2555 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2556 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2557 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2558 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2559 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2560 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2561 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2562 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2563 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2564 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2565 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2566 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2567 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2568 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2569 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2570 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2571 | &calldata->arg.seq_args, |
| 2572 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2573 | task) != 0) |
| 2574 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2575 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2576 | return; |
| 2577 | out_no_action: |
| 2578 | task->tk_action = NULL; |
| 2579 | out_wait: |
| 2580 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2583 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2584 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2585 | .rpc_call_done = nfs4_close_done, |
| 2586 | .rpc_release = nfs4_free_closedata, |
| 2587 | }; |
| 2588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | /* |
| 2590 | * It is possible for data to be read/written from a mem-mapped file |
| 2591 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2592 | * This means that we can't safely call nfsv4 close on a file until |
| 2593 | * the inode is cleared. This in turn means that we are not good |
| 2594 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2595 | * share state even when we are done with one of the three share |
| 2596 | * stateid's in the inode. |
| 2597 | * |
| 2598 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2599 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2600 | 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] | 2601 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2602 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2604 | struct nfs4_state_owner *sp = state->owner; |
| 2605 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2606 | struct rpc_message msg = { |
| 2607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2608 | .rpc_cred = state->owner->so_cred, |
| 2609 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2610 | struct rpc_task_setup task_setup_data = { |
| 2611 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2612 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2613 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2614 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2615 | .flags = RPC_TASK_ASYNC, |
| 2616 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2617 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2619 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2620 | &task_setup_data.rpc_client, &msg); |
| 2621 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2622 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2624 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2625 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2626 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2628 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2629 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2631 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2632 | if (calldata->arg.seqid == NULL) |
| 2633 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2634 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2635 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2636 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2637 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2638 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2639 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2640 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2641 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2642 | msg.rpc_argp = &calldata->arg; |
| 2643 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2644 | task_setup_data.callback_data = calldata; |
| 2645 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2646 | if (IS_ERR(task)) |
| 2647 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2648 | status = 0; |
| 2649 | if (wait) |
| 2650 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2651 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2652 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2653 | out_free_calldata: |
| 2654 | kfree(calldata); |
| 2655 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2656 | nfs4_put_open_state(state); |
| 2657 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2658 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2661 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2662 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2665 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2666 | |
| 2667 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2669 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 2670 | state = nfs4_do_open(dir, ctx, open_flags, attr, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2671 | |
| 2672 | nfs4_label_release_security(label); |
| 2673 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2674 | if (IS_ERR(state)) |
| 2675 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2676 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2679 | 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] | 2680 | { |
| 2681 | if (ctx->state == NULL) |
| 2682 | return; |
| 2683 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2684 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2685 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2686 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
| 2689 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2690 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2691 | struct nfs4_server_caps_arg args = { |
| 2692 | .fhandle = fhandle, |
| 2693 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | struct nfs4_server_caps_res res = {}; |
| 2695 | struct rpc_message msg = { |
| 2696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2697 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | .rpc_resp = &res, |
| 2699 | }; |
| 2700 | int status; |
| 2701 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2702 | 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] | 2703 | if (status == 0) { |
| 2704 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2705 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2706 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2707 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2708 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2709 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2711 | server->caps |= NFS_CAP_ACLS; |
| 2712 | if (res.has_links != 0) |
| 2713 | server->caps |= NFS_CAP_HARDLINKS; |
| 2714 | if (res.has_symlinks != 0) |
| 2715 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2716 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2717 | server->caps |= NFS_CAP_FILEID; |
| 2718 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2719 | server->caps |= NFS_CAP_MODE; |
| 2720 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2721 | server->caps |= NFS_CAP_NLINK; |
| 2722 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2723 | server->caps |= NFS_CAP_OWNER; |
| 2724 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2725 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2726 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2727 | server->caps |= NFS_CAP_ATIME; |
| 2728 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2729 | server->caps |= NFS_CAP_CTIME; |
| 2730 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2731 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2732 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2733 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2734 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2735 | #endif |
| 2736 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2737 | sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2738 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2739 | if (server->caps & NFS_CAP_SECURITY_LABEL) { |
| 2740 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2741 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2742 | } |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2743 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2744 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2745 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2747 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | return status; |
| 2751 | } |
| 2752 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2753 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | { |
| 2755 | struct nfs4_exception exception = { }; |
| 2756 | int err; |
| 2757 | do { |
| 2758 | err = nfs4_handle_exception(server, |
| 2759 | _nfs4_server_capabilities(server, fhandle), |
| 2760 | &exception); |
| 2761 | } while (exception.retry); |
| 2762 | return err; |
| 2763 | } |
| 2764 | |
| 2765 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2766 | struct nfs_fsinfo *info) |
| 2767 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2768 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2770 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | }; |
| 2772 | struct nfs4_lookup_res res = { |
| 2773 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2774 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | .fh = fhandle, |
| 2776 | }; |
| 2777 | struct rpc_message msg = { |
| 2778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2779 | .rpc_argp = &args, |
| 2780 | .rpc_resp = &res, |
| 2781 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2782 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2783 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2784 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2785 | /* |
| 2786 | * Process the label in the upcoming getfattr |
| 2787 | */ |
| 2788 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2789 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2790 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2791 | 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] | 2792 | } |
| 2793 | |
| 2794 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2795 | struct nfs_fsinfo *info) |
| 2796 | { |
| 2797 | struct nfs4_exception exception = { }; |
| 2798 | int err; |
| 2799 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2800 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2801 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2802 | switch (err) { |
| 2803 | case 0: |
| 2804 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2805 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2806 | default: |
| 2807 | err = nfs4_handle_exception(server, err, &exception); |
| 2808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2810 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | return err; |
| 2812 | } |
| 2813 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2814 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2815 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2816 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2817 | struct rpc_auth_create_args auth_args = { |
| 2818 | .pseudoflavor = flavor, |
| 2819 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2820 | struct rpc_auth *auth; |
| 2821 | int ret; |
| 2822 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2823 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2824 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2825 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2826 | goto out; |
| 2827 | } |
| 2828 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2829 | out: |
| 2830 | return ret; |
| 2831 | } |
| 2832 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2833 | /* |
| 2834 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2835 | * |
| 2836 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2837 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2838 | * |
| 2839 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2840 | * negative errno value. |
| 2841 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2842 | 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] | 2843 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2845 | /* Per 3530bis 15.33.5 */ |
| 2846 | static const rpc_authflavor_t flav_array[] = { |
| 2847 | RPC_AUTH_GSS_KRB5P, |
| 2848 | RPC_AUTH_GSS_KRB5I, |
| 2849 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2850 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2851 | RPC_AUTH_NULL, |
| 2852 | }; |
| 2853 | int status = -EPERM; |
| 2854 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2856 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2857 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2858 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2859 | continue; |
| 2860 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2861 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2862 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2863 | /* |
| 2864 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2865 | * to access the mount. It could also mean that we tried to mount |
| 2866 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2867 | * existing mount programs don't handle -EACCES very well so it should |
| 2868 | * be mapped to -EPERM instead. |
| 2869 | */ |
| 2870 | if (status == -EACCES) |
| 2871 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2872 | return status; |
| 2873 | } |
| 2874 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2875 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2876 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2877 | { |
| 2878 | int mv = server->nfs_client->cl_minorversion; |
| 2879 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2880 | } |
| 2881 | |
| 2882 | /** |
| 2883 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2884 | * @server: initialized nfs_server handle |
| 2885 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2886 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2887 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2888 | * |
| 2889 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2890 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2891 | 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] | 2892 | struct nfs_fsinfo *info, |
| 2893 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2894 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2895 | int status; |
| 2896 | |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2897 | switch (auth_probe) { |
| 2898 | case false: |
| 2899 | status = nfs4_lookup_root(server, fhandle, info); |
| 2900 | if (status != -NFS4ERR_WRONGSEC) |
| 2901 | break; |
| 2902 | /* Did user force a 'sec=' mount option? */ |
| 2903 | if (server->flags & NFS_MOUNT_SECFLAVOUR) |
| 2904 | break; |
| 2905 | default: |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2906 | status = nfs4_do_find_root_sec(server, fhandle, info); |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2907 | } |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2908 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | if (status == 0) |
| 2910 | status = nfs4_server_capabilities(server, fhandle); |
| 2911 | if (status == 0) |
| 2912 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2913 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2914 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2917 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2918 | struct nfs_fsinfo *info) |
| 2919 | { |
| 2920 | int error; |
| 2921 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2922 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2923 | |
| 2924 | error = nfs4_server_capabilities(server, mntfh); |
| 2925 | if (error < 0) { |
| 2926 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2927 | return error; |
| 2928 | } |
| 2929 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2930 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 2931 | if (IS_ERR(label)) |
| 2932 | return PTR_ERR(label); |
| 2933 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2934 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2935 | if (error < 0) { |
| 2936 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2937 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2941 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2942 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2943 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2944 | err_free_label: |
| 2945 | nfs4_label_free(label); |
| 2946 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2947 | return error; |
| 2948 | } |
| 2949 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2950 | /* |
| 2951 | * Get locations and (maybe) other attributes of a referral. |
| 2952 | * Note that we'll actually follow the referral later when |
| 2953 | * we detect fsid mismatch in inode revalidation |
| 2954 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2955 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2956 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2957 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2958 | { |
| 2959 | int status = -ENOMEM; |
| 2960 | struct page *page = NULL; |
| 2961 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2962 | |
| 2963 | page = alloc_page(GFP_KERNEL); |
| 2964 | if (page == NULL) |
| 2965 | goto out; |
| 2966 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2967 | if (locations == NULL) |
| 2968 | goto out; |
| 2969 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2970 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2971 | if (status != 0) |
| 2972 | goto out; |
| 2973 | /* Make sure server returned a different fsid for the referral */ |
| 2974 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2975 | dprintk("%s: server did not return a different fsid for" |
| 2976 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2977 | status = -EIO; |
| 2978 | goto out; |
| 2979 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2980 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2981 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2982 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2983 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2984 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2985 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2986 | out: |
| 2987 | if (page) |
| 2988 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2989 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2990 | return status; |
| 2991 | } |
| 2992 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2993 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2994 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | { |
| 2996 | struct nfs4_getattr_arg args = { |
| 2997 | .fh = fhandle, |
| 2998 | .bitmask = server->attr_bitmask, |
| 2999 | }; |
| 3000 | struct nfs4_getattr_res res = { |
| 3001 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3002 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | .server = server, |
| 3004 | }; |
| 3005 | struct rpc_message msg = { |
| 3006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3007 | .rpc_argp = &args, |
| 3008 | .rpc_resp = &res, |
| 3009 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3010 | |
| 3011 | args.bitmask = nfs4_bitmask(server, label); |
| 3012 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3013 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3014 | 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] | 3015 | } |
| 3016 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3017 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3018 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | { |
| 3020 | struct nfs4_exception exception = { }; |
| 3021 | int err; |
| 3022 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3023 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3024 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3025 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | &exception); |
| 3027 | } while (exception.retry); |
| 3028 | return err; |
| 3029 | } |
| 3030 | |
| 3031 | /* |
| 3032 | * The file is not closed if it is opened due to the a request to change |
| 3033 | * the size of the file. The open call will not be needed once the |
| 3034 | * VFS layer lookup-intents are implemented. |
| 3035 | * |
| 3036 | * Close is called when the inode is destroyed. |
| 3037 | * If we haven't opened the file for O_WRONLY, we |
| 3038 | * need to in the size_change case to obtain a stateid. |
| 3039 | * |
| 3040 | * Got race? |
| 3041 | * Because OPEN is always done by name in nfsv4, it is |
| 3042 | * possible that we opened a different file by the same |
| 3043 | * name. We can recognize this race condition, but we |
| 3044 | * can't do anything about it besides returning an error. |
| 3045 | * |
| 3046 | * This will be fixed with VFS changes (lookup-intent). |
| 3047 | */ |
| 3048 | static int |
| 3049 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3050 | struct iattr *sattr) |
| 3051 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3052 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3053 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3054 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3055 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | int status; |
| 3057 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3058 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3059 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3060 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3061 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3063 | /* Deal with open(O_TRUNC) */ |
| 3064 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3065 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3066 | |
| 3067 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3068 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3069 | return 0; |
| 3070 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3071 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3072 | if (sattr->ia_valid & ATTR_FILE) { |
| 3073 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3074 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3075 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3076 | if (ctx) { |
| 3077 | cred = ctx->cred; |
| 3078 | state = ctx->state; |
| 3079 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3080 | } |
| 3081 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3082 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3083 | if (IS_ERR(label)) |
| 3084 | return PTR_ERR(label); |
| 3085 | |
| 3086 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3087 | if (status == 0) { |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 3088 | nfs_setattr_update_inode(inode, sattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3089 | nfs_setsecurity(inode, fattr, label); |
| 3090 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3091 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | return status; |
| 3093 | } |
| 3094 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3095 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3096 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3097 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3098 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3099 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3100 | int status; |
| 3101 | struct nfs4_lookup_arg args = { |
| 3102 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3103 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3104 | .name = name, |
| 3105 | }; |
| 3106 | struct nfs4_lookup_res res = { |
| 3107 | .server = server, |
| 3108 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3109 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3110 | .fh = fhandle, |
| 3111 | }; |
| 3112 | struct rpc_message msg = { |
| 3113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3114 | .rpc_argp = &args, |
| 3115 | .rpc_resp = &res, |
| 3116 | }; |
| 3117 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3118 | args.bitmask = nfs4_bitmask(server, label); |
| 3119 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3120 | nfs_fattr_init(fattr); |
| 3121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3123 | 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] | 3124 | dprintk("NFS reply lookup: %d\n", status); |
| 3125 | return status; |
| 3126 | } |
| 3127 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3128 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3129 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3130 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3131 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3132 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3133 | fattr->nlink = 2; |
| 3134 | } |
| 3135 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3136 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3137 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3138 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3139 | { |
| 3140 | struct nfs4_exception exception = { }; |
| 3141 | struct rpc_clnt *client = *clnt; |
| 3142 | int err; |
| 3143 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3144 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3145 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3146 | switch (err) { |
| 3147 | case -NFS4ERR_BADNAME: |
| 3148 | err = -ENOENT; |
| 3149 | goto out; |
| 3150 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3151 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3152 | goto out; |
| 3153 | case -NFS4ERR_WRONGSEC: |
| 3154 | err = -EPERM; |
| 3155 | if (client != *clnt) |
| 3156 | goto out; |
Trond Myklebust | 41d058c | 2013-09-07 17:49:05 -0400 | [diff] [blame^] | 3157 | /* No security negotiation if the user specified 'sec=' */ |
| 3158 | if (NFS_SERVER(dir)->flags & NFS_MOUNT_SECFLAVOUR) |
| 3159 | goto out; |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3160 | client = nfs4_create_sec_client(client, dir, name); |
| 3161 | if (IS_ERR(client)) |
| 3162 | return PTR_ERR(client); |
| 3163 | |
| 3164 | exception.retry = 1; |
| 3165 | break; |
| 3166 | default: |
| 3167 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3168 | } |
| 3169 | } while (exception.retry); |
| 3170 | |
| 3171 | out: |
| 3172 | if (err == 0) |
| 3173 | *clnt = client; |
| 3174 | else if (client != *clnt) |
| 3175 | rpc_shutdown_client(client); |
| 3176 | |
| 3177 | return err; |
| 3178 | } |
| 3179 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3180 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3181 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3182 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3184 | int status; |
| 3185 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3186 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3187 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3188 | if (client != NFS_CLIENT(dir)) { |
| 3189 | rpc_shutdown_client(client); |
| 3190 | nfs_fixup_secinfo_attributes(fattr); |
| 3191 | } |
| 3192 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3195 | struct rpc_clnt * |
| 3196 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3197 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3198 | { |
| 3199 | int status; |
| 3200 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 3201 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3202 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3203 | if (status < 0) { |
| 3204 | rpc_shutdown_client(client); |
| 3205 | return ERR_PTR(status); |
| 3206 | } |
| 3207 | return client; |
| 3208 | } |
| 3209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3211 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3212 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | struct nfs4_accessargs args = { |
| 3214 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3215 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3217 | struct nfs4_accessres res = { |
| 3218 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3219 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | struct rpc_message msg = { |
| 3221 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3222 | .rpc_argp = &args, |
| 3223 | .rpc_resp = &res, |
| 3224 | .rpc_cred = entry->cred, |
| 3225 | }; |
| 3226 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3227 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | |
| 3229 | /* |
| 3230 | * Determine which access bits we want to ask for... |
| 3231 | */ |
| 3232 | if (mode & MAY_READ) |
| 3233 | args.access |= NFS4_ACCESS_READ; |
| 3234 | if (S_ISDIR(inode->i_mode)) { |
| 3235 | if (mode & MAY_WRITE) |
| 3236 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3237 | if (mode & MAY_EXEC) |
| 3238 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3239 | } else { |
| 3240 | if (mode & MAY_WRITE) |
| 3241 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3242 | if (mode & MAY_EXEC) |
| 3243 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3244 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3245 | |
| 3246 | res.fattr = nfs_alloc_fattr(); |
| 3247 | if (res.fattr == NULL) |
| 3248 | return -ENOMEM; |
| 3249 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3250 | 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] | 3251 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3252 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3253 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3255 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | return status; |
| 3257 | } |
| 3258 | |
| 3259 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3260 | { |
| 3261 | struct nfs4_exception exception = { }; |
| 3262 | int err; |
| 3263 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3264 | err = _nfs4_proc_access(inode, entry); |
| 3265 | trace_nfs4_access(inode, err); |
| 3266 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | &exception); |
| 3268 | } while (exception.retry); |
| 3269 | return err; |
| 3270 | } |
| 3271 | |
| 3272 | /* |
| 3273 | * TODO: For the time being, we don't try to get any attributes |
| 3274 | * along with any of the zero-copy operations READ, READDIR, |
| 3275 | * READLINK, WRITE. |
| 3276 | * |
| 3277 | * In the case of the first three, we want to put the GETATTR |
| 3278 | * after the read-type operation -- this is because it is hard |
| 3279 | * to predict the length of a GETATTR response in v4, and thus |
| 3280 | * align the READ data correctly. This means that the GETATTR |
| 3281 | * may end up partially falling into the page cache, and we should |
| 3282 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3283 | * To do this efficiently, we need to know the total length |
| 3284 | * of data received, which doesn't seem to be available outside |
| 3285 | * of the RPC layer. |
| 3286 | * |
| 3287 | * In the case of WRITE, we also want to put the GETATTR after |
| 3288 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3289 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | * |
| 3291 | * Both of these changes to the XDR layer would in fact be quite |
| 3292 | * minor, but I decided to leave them for a subsequent patch. |
| 3293 | */ |
| 3294 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3295 | unsigned int pgbase, unsigned int pglen) |
| 3296 | { |
| 3297 | struct nfs4_readlink args = { |
| 3298 | .fh = NFS_FH(inode), |
| 3299 | .pgbase = pgbase, |
| 3300 | .pglen = pglen, |
| 3301 | .pages = &page, |
| 3302 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3303 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | struct rpc_message msg = { |
| 3305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3306 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3307 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | }; |
| 3309 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3310 | 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] | 3311 | } |
| 3312 | |
| 3313 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3314 | unsigned int pgbase, unsigned int pglen) |
| 3315 | { |
| 3316 | struct nfs4_exception exception = { }; |
| 3317 | int err; |
| 3318 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3319 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3320 | trace_nfs4_readlink(inode, err); |
| 3321 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | &exception); |
| 3323 | } while (exception.retry); |
| 3324 | return err; |
| 3325 | } |
| 3326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3328 | * 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] | 3329 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | static int |
| 3331 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3332 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3334 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3335 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | int status = 0; |
| 3338 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3339 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3340 | if (IS_ERR(ctx)) |
| 3341 | return PTR_ERR(ctx); |
| 3342 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3343 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3344 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3345 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 959d921 | 2013-06-28 16:29:51 -0400 | [diff] [blame] | 3346 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | if (IS_ERR(state)) { |
| 3348 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3349 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3352 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3353 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | return status; |
| 3355 | } |
| 3356 | |
| 3357 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3358 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3359 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3360 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3362 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3364 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3365 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3366 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3368 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3369 | .rpc_argp = &args, |
| 3370 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3372 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3373 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3374 | 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] | 3375 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3376 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | return status; |
| 3378 | } |
| 3379 | |
| 3380 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3381 | { |
| 3382 | struct nfs4_exception exception = { }; |
| 3383 | int err; |
| 3384 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3385 | err = _nfs4_proc_remove(dir, name); |
| 3386 | trace_nfs4_remove(dir, name, err); |
| 3387 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | &exception); |
| 3389 | } while (exception.retry); |
| 3390 | return err; |
| 3391 | } |
| 3392 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3393 | 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] | 3394 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3395 | struct nfs_server *server = NFS_SERVER(dir); |
| 3396 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3397 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3399 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3401 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3402 | |
| 3403 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3406 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3407 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3408 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3409 | &data->args.seq_args, |
| 3410 | &data->res.seq_res, |
| 3411 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3414 | 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] | 3415 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3416 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3417 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3418 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3419 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3420 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3421 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3422 | return 0; |
| 3423 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3424 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3427 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3428 | { |
| 3429 | struct nfs_server *server = NFS_SERVER(dir); |
| 3430 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3431 | struct nfs_renameres *res = msg->rpc_resp; |
| 3432 | |
| 3433 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3434 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3435 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3436 | } |
| 3437 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3438 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3439 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3440 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3441 | &data->args.seq_args, |
| 3442 | &data->res.seq_res, |
| 3443 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3447 | struct inode *new_dir) |
| 3448 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3449 | struct nfs_renamedata *data = task->tk_calldata; |
| 3450 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3451 | |
| 3452 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3453 | return 0; |
| 3454 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3455 | return 0; |
| 3456 | |
| 3457 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3458 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3459 | return 1; |
| 3460 | } |
| 3461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3463 | struct inode *new_dir, struct qstr *new_name) |
| 3464 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3465 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3466 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | .old_dir = NFS_FH(old_dir), |
| 3468 | .new_dir = NFS_FH(new_dir), |
| 3469 | .old_name = old_name, |
| 3470 | .new_name = new_name, |
| 3471 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3472 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3473 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3474 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | struct rpc_message msg = { |
| 3476 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3477 | .rpc_argp = &arg, |
| 3478 | .rpc_resp = &res, |
| 3479 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3480 | int status = -ENOMEM; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3481 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3482 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | if (!status) { |
| 3484 | update_changeattr(old_dir, &res.old_cinfo); |
| 3485 | update_changeattr(new_dir, &res.new_cinfo); |
| 3486 | } |
| 3487 | return status; |
| 3488 | } |
| 3489 | |
| 3490 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3491 | struct inode *new_dir, struct qstr *new_name) |
| 3492 | { |
| 3493 | struct nfs4_exception exception = { }; |
| 3494 | int err; |
| 3495 | do { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3496 | err = _nfs4_proc_rename(old_dir, old_name, |
| 3497 | new_dir, new_name); |
| 3498 | trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err); |
| 3499 | err = nfs4_handle_exception(NFS_SERVER(old_dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | &exception); |
| 3501 | } while (exception.retry); |
| 3502 | return err; |
| 3503 | } |
| 3504 | |
| 3505 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3506 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3507 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | struct nfs4_link_arg arg = { |
| 3509 | .fh = NFS_FH(inode), |
| 3510 | .dir_fh = NFS_FH(dir), |
| 3511 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3512 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3514 | struct nfs4_link_res res = { |
| 3515 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3516 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3517 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | struct rpc_message msg = { |
| 3519 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3520 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3521 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3523 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3525 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3526 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3527 | goto out; |
| 3528 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3529 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3530 | if (IS_ERR(res.label)) { |
| 3531 | status = PTR_ERR(res.label); |
| 3532 | goto out; |
| 3533 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3534 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3535 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3536 | 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] | 3537 | if (!status) { |
| 3538 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3539 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3540 | if (!status) |
| 3541 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3542 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3543 | |
| 3544 | |
| 3545 | nfs4_label_free(res.label); |
| 3546 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3547 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3548 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | return status; |
| 3550 | } |
| 3551 | |
| 3552 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3553 | { |
| 3554 | struct nfs4_exception exception = { }; |
| 3555 | int err; |
| 3556 | do { |
| 3557 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3558 | _nfs4_proc_link(inode, dir, name), |
| 3559 | &exception); |
| 3560 | } while (exception.retry); |
| 3561 | return err; |
| 3562 | } |
| 3563 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3564 | struct nfs4_createdata { |
| 3565 | struct rpc_message msg; |
| 3566 | struct nfs4_create_arg arg; |
| 3567 | struct nfs4_create_res res; |
| 3568 | struct nfs_fh fh; |
| 3569 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3570 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3571 | }; |
| 3572 | |
| 3573 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3574 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3575 | { |
| 3576 | struct nfs4_createdata *data; |
| 3577 | |
| 3578 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3579 | if (data != NULL) { |
| 3580 | struct nfs_server *server = NFS_SERVER(dir); |
| 3581 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3582 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3583 | if (IS_ERR(data->label)) |
| 3584 | goto out_free; |
| 3585 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3586 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3587 | data->msg.rpc_argp = &data->arg; |
| 3588 | data->msg.rpc_resp = &data->res; |
| 3589 | data->arg.dir_fh = NFS_FH(dir); |
| 3590 | data->arg.server = server; |
| 3591 | data->arg.name = name; |
| 3592 | data->arg.attrs = sattr; |
| 3593 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3594 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3595 | data->res.server = server; |
| 3596 | data->res.fh = &data->fh; |
| 3597 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3598 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3599 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3600 | } |
| 3601 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3602 | out_free: |
| 3603 | kfree(data); |
| 3604 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3608 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3609 | 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] | 3610 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3611 | if (status == 0) { |
| 3612 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3613 | 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] | 3614 | } |
| 3615 | return status; |
| 3616 | } |
| 3617 | |
| 3618 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3619 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3620 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3621 | kfree(data); |
| 3622 | } |
| 3623 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3624 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3625 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3626 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3628 | struct nfs4_createdata *data; |
| 3629 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3631 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3632 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3633 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3634 | status = -ENOMEM; |
| 3635 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3636 | if (data == NULL) |
| 3637 | goto out; |
| 3638 | |
| 3639 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3640 | data->arg.u.symlink.pages = &page; |
| 3641 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3642 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3644 | status = nfs4_do_create(dir, dentry, data); |
| 3645 | |
| 3646 | nfs4_free_createdata(data); |
| 3647 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | return status; |
| 3649 | } |
| 3650 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3651 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3652 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | { |
| 3654 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3655 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3657 | |
| 3658 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3661 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3662 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3663 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | &exception); |
| 3665 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3666 | |
| 3667 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | return err; |
| 3669 | } |
| 3670 | |
| 3671 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3672 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3674 | struct nfs4_createdata *data; |
| 3675 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3677 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3678 | if (data == NULL) |
| 3679 | goto out; |
| 3680 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3681 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3682 | status = nfs4_do_create(dir, dentry, data); |
| 3683 | |
| 3684 | nfs4_free_createdata(data); |
| 3685 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | return status; |
| 3687 | } |
| 3688 | |
| 3689 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3690 | struct iattr *sattr) |
| 3691 | { |
| 3692 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3693 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3695 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3696 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3697 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3698 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3700 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3701 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3702 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | &exception); |
| 3704 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3705 | nfs4_label_release_security(label); |
| 3706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | return err; |
| 3708 | } |
| 3709 | |
| 3710 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3711 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | { |
| 3713 | struct inode *dir = dentry->d_inode; |
| 3714 | struct nfs4_readdir_arg args = { |
| 3715 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3716 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | .pgbase = 0, |
| 3718 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3719 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3720 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | }; |
| 3722 | struct nfs4_readdir_res res; |
| 3723 | struct rpc_message msg = { |
| 3724 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3725 | .rpc_argp = &args, |
| 3726 | .rpc_resp = &res, |
| 3727 | .rpc_cred = cred, |
| 3728 | }; |
| 3729 | int status; |
| 3730 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3731 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3732 | dentry->d_parent->d_name.name, |
| 3733 | dentry->d_name.name, |
| 3734 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3735 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3737 | 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] | 3738 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3739 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3740 | status += args.pgbase; |
| 3741 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3742 | |
| 3743 | nfs_invalidate_atime(dir); |
| 3744 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3745 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | return status; |
| 3747 | } |
| 3748 | |
| 3749 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3750 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | { |
| 3752 | struct nfs4_exception exception = { }; |
| 3753 | int err; |
| 3754 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3755 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3756 | pages, count, plus); |
| 3757 | trace_nfs4_readdir(dentry->d_inode, err); |
| 3758 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | &exception); |
| 3760 | } while (exception.retry); |
| 3761 | return err; |
| 3762 | } |
| 3763 | |
| 3764 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3765 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3767 | struct nfs4_createdata *data; |
| 3768 | int mode = sattr->ia_mode; |
| 3769 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3771 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3772 | if (data == NULL) |
| 3773 | goto out; |
| 3774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3776 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3778 | data->arg.ftype = NF4BLK; |
| 3779 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3780 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | } |
| 3782 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3783 | data->arg.ftype = NF4CHR; |
| 3784 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3785 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3786 | } else if (!S_ISSOCK(mode)) { |
| 3787 | status = -EINVAL; |
| 3788 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3790 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3792 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3793 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3794 | nfs4_free_createdata(data); |
| 3795 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | return status; |
| 3797 | } |
| 3798 | |
| 3799 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3800 | struct iattr *sattr, dev_t rdev) |
| 3801 | { |
| 3802 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3803 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3805 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3806 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3807 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3808 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3810 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3811 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3812 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | &exception); |
| 3814 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3815 | |
| 3816 | nfs4_label_release_security(label); |
| 3817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | return err; |
| 3819 | } |
| 3820 | |
| 3821 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3822 | struct nfs_fsstat *fsstat) |
| 3823 | { |
| 3824 | struct nfs4_statfs_arg args = { |
| 3825 | .fh = fhandle, |
| 3826 | .bitmask = server->attr_bitmask, |
| 3827 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3828 | struct nfs4_statfs_res res = { |
| 3829 | .fsstat = fsstat, |
| 3830 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | struct rpc_message msg = { |
| 3832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3833 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3834 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | }; |
| 3836 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3837 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3838 | 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] | 3839 | } |
| 3840 | |
| 3841 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3842 | { |
| 3843 | struct nfs4_exception exception = { }; |
| 3844 | int err; |
| 3845 | do { |
| 3846 | err = nfs4_handle_exception(server, |
| 3847 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3848 | &exception); |
| 3849 | } while (exception.retry); |
| 3850 | return err; |
| 3851 | } |
| 3852 | |
| 3853 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3854 | struct nfs_fsinfo *fsinfo) |
| 3855 | { |
| 3856 | struct nfs4_fsinfo_arg args = { |
| 3857 | .fh = fhandle, |
| 3858 | .bitmask = server->attr_bitmask, |
| 3859 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3860 | struct nfs4_fsinfo_res res = { |
| 3861 | .fsinfo = fsinfo, |
| 3862 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | struct rpc_message msg = { |
| 3864 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3865 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3866 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | }; |
| 3868 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3869 | 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] | 3870 | } |
| 3871 | |
| 3872 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3873 | { |
| 3874 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3875 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | int err; |
| 3877 | |
| 3878 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3879 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3880 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3881 | if (err == 0) { |
| 3882 | struct nfs_client *clp = server->nfs_client; |
| 3883 | |
| 3884 | spin_lock(&clp->cl_lock); |
| 3885 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3886 | clp->cl_last_renewal = now; |
| 3887 | spin_unlock(&clp->cl_lock); |
| 3888 | break; |
| 3889 | } |
| 3890 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | } while (exception.retry); |
| 3892 | return err; |
| 3893 | } |
| 3894 | |
| 3895 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3896 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3897 | int error; |
| 3898 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3899 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3900 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3901 | if (error == 0) { |
| 3902 | /* block layout checks this! */ |
| 3903 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3904 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3905 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3906 | |
| 3907 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3911 | struct nfs_pathconf *pathconf) |
| 3912 | { |
| 3913 | struct nfs4_pathconf_arg args = { |
| 3914 | .fh = fhandle, |
| 3915 | .bitmask = server->attr_bitmask, |
| 3916 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3917 | struct nfs4_pathconf_res res = { |
| 3918 | .pathconf = pathconf, |
| 3919 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | struct rpc_message msg = { |
| 3921 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3922 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3923 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | }; |
| 3925 | |
| 3926 | /* None of the pathconf attributes are mandatory to implement */ |
| 3927 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3928 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3929 | return 0; |
| 3930 | } |
| 3931 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3932 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3933 | 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] | 3934 | } |
| 3935 | |
| 3936 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3937 | struct nfs_pathconf *pathconf) |
| 3938 | { |
| 3939 | struct nfs4_exception exception = { }; |
| 3940 | int err; |
| 3941 | |
| 3942 | do { |
| 3943 | err = nfs4_handle_exception(server, |
| 3944 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3945 | &exception); |
| 3946 | } while (exception.retry); |
| 3947 | return err; |
| 3948 | } |
| 3949 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3950 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3951 | const struct nfs_open_context *ctx, |
| 3952 | const struct nfs_lock_context *l_ctx, |
| 3953 | fmode_t fmode) |
| 3954 | { |
| 3955 | const struct nfs_lockowner *lockowner = NULL; |
| 3956 | |
| 3957 | if (l_ctx != NULL) |
| 3958 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3959 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3960 | } |
| 3961 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3962 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3963 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3964 | const struct nfs_open_context *ctx, |
| 3965 | const struct nfs_lock_context *l_ctx, |
| 3966 | fmode_t fmode) |
| 3967 | { |
| 3968 | nfs4_stateid current_stateid; |
| 3969 | |
| 3970 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3971 | return false; |
| 3972 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3973 | } |
| 3974 | |
| 3975 | static bool nfs4_error_stateid_expired(int err) |
| 3976 | { |
| 3977 | switch (err) { |
| 3978 | case -NFS4ERR_DELEG_REVOKED: |
| 3979 | case -NFS4ERR_ADMIN_REVOKED: |
| 3980 | case -NFS4ERR_BAD_STATEID: |
| 3981 | case -NFS4ERR_STALE_STATEID: |
| 3982 | case -NFS4ERR_OLD_STATEID: |
| 3983 | case -NFS4ERR_OPENMODE: |
| 3984 | case -NFS4ERR_EXPIRED: |
| 3985 | return true; |
| 3986 | } |
| 3987 | return false; |
| 3988 | } |
| 3989 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3990 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3991 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3992 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3993 | } |
| 3994 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3995 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3997 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 3999 | trace_nfs4_read(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4000 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4001 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4002 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4004 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4005 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4007 | renew_lease(server, data->timestamp); |
| 4008 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4011 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 4012 | struct nfs_readargs *args) |
| 4013 | { |
| 4014 | |
| 4015 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4016 | nfs4_stateid_is_current(&args->stateid, |
| 4017 | args->context, |
| 4018 | args->lock_context, |
| 4019 | FMODE_READ)) |
| 4020 | return false; |
| 4021 | rpc_restart_call_prepare(task); |
| 4022 | return true; |
| 4023 | } |
| 4024 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4025 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 4026 | { |
| 4027 | |
| 4028 | dprintk("--> %s\n", __func__); |
| 4029 | |
| 4030 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4031 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4032 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 4033 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4034 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 4035 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4038 | static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4041 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4042 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4043 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4046 | static int nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4047 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4048 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4049 | &data->args.seq_args, |
| 4050 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4051 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4052 | return 0; |
| 4053 | if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4054 | data->args.lock_context, FMODE_READ) == -EIO) |
| 4055 | return -EIO; |
| 4056 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags))) |
| 4057 | return -EIO; |
| 4058 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4061 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4063 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4065 | trace_nfs4_write(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4066 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4067 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4068 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4070 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4072 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4073 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4074 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4077 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 4078 | struct nfs_writeargs *args) |
| 4079 | { |
| 4080 | |
| 4081 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4082 | nfs4_stateid_is_current(&args->stateid, |
| 4083 | args->context, |
| 4084 | args->lock_context, |
| 4085 | FMODE_WRITE)) |
| 4086 | return false; |
| 4087 | rpc_restart_call_prepare(task); |
| 4088 | return true; |
| 4089 | } |
| 4090 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4091 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 4092 | { |
| 4093 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4094 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4095 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 4096 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4097 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 4098 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4101 | static |
| 4102 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4103 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4104 | const struct nfs_pgio_header *hdr = data->header; |
| 4105 | |
| 4106 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 4107 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 4108 | return false; |
| 4109 | /* Otherwise, request attributes if and only if we don't hold |
| 4110 | * a delegation |
| 4111 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4112 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4113 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4114 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4115 | static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4117 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4118 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4119 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4120 | data->args.bitmask = NULL; |
| 4121 | data->res.fattr = NULL; |
| 4122 | } else |
| 4123 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4124 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4125 | if (!data->write_done_cb) |
| 4126 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4127 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | data->timestamp = jiffies; |
| 4129 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4130 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4131 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4134 | static int nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 4135 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4136 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4137 | &data->args.seq_args, |
| 4138 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4139 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4140 | return 0; |
| 4141 | if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 4142 | data->args.lock_context, FMODE_WRITE) == -EIO) |
| 4143 | return -EIO; |
| 4144 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags))) |
| 4145 | return -EIO; |
| 4146 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4149 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4150 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4151 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4152 | &data->args.seq_args, |
| 4153 | &data->res.seq_res, |
| 4154 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4157 | 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] | 4158 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4160 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4161 | trace_nfs4_commit(data, task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4162 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4163 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4164 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4166 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4169 | 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] | 4170 | { |
| 4171 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4172 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4173 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4174 | } |
| 4175 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4176 | 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] | 4177 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4178 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4179 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4180 | if (data->commit_done_cb == NULL) |
| 4181 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4182 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4183 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4184 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4187 | struct nfs4_renewdata { |
| 4188 | struct nfs_client *client; |
| 4189 | unsigned long timestamp; |
| 4190 | }; |
| 4191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | /* |
| 4193 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4194 | * standalone procedure for queueing an asynchronous RENEW. |
| 4195 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4196 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4197 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4198 | struct nfs4_renewdata *data = calldata; |
| 4199 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4200 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4201 | if (atomic_read(&clp->cl_count) > 1) |
| 4202 | nfs4_schedule_state_renewal(clp); |
| 4203 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4204 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4205 | } |
| 4206 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4207 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4209 | struct nfs4_renewdata *data = calldata; |
| 4210 | struct nfs_client *clp = data->client; |
| 4211 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4213 | trace_nfs4_renew_async(clp, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4215 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4216 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4217 | return; |
| 4218 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4219 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4220 | return; |
| 4221 | } |
| 4222 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4224 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4227 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4228 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4229 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4230 | }; |
| 4231 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4232 | 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] | 4233 | { |
| 4234 | struct rpc_message msg = { |
| 4235 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4236 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4237 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4239 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4241 | if (renew_flags == 0) |
| 4242 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4243 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4244 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4245 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4246 | if (data == NULL) |
| 4247 | return -ENOMEM; |
| 4248 | data->client = clp; |
| 4249 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4250 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4251 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4254 | 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] | 4255 | { |
| 4256 | struct rpc_message msg = { |
| 4257 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4258 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4259 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | }; |
| 4261 | unsigned long now = jiffies; |
| 4262 | int status; |
| 4263 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4264 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | if (status < 0) |
| 4266 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4267 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | return 0; |
| 4269 | } |
| 4270 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4271 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4272 | { |
| 4273 | return (server->caps & NFS_CAP_ACLS) |
| 4274 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 4275 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 4276 | } |
| 4277 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4278 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4279 | * 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] | 4280 | * the stack. |
| 4281 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4282 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4283 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4284 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4285 | struct page **pages, unsigned int *pgbase) |
| 4286 | { |
| 4287 | struct page *newpage, **spages; |
| 4288 | int rc = 0; |
| 4289 | size_t len; |
| 4290 | spages = pages; |
| 4291 | |
| 4292 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4293 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4294 | newpage = alloc_page(GFP_KERNEL); |
| 4295 | |
| 4296 | if (newpage == NULL) |
| 4297 | goto unwind; |
| 4298 | memcpy(page_address(newpage), buf, len); |
| 4299 | buf += len; |
| 4300 | buflen -= len; |
| 4301 | *pages++ = newpage; |
| 4302 | rc++; |
| 4303 | } while (buflen != 0); |
| 4304 | |
| 4305 | return rc; |
| 4306 | |
| 4307 | unwind: |
| 4308 | for(; rc > 0; rc--) |
| 4309 | __free_page(spages[rc-1]); |
| 4310 | return -ENOMEM; |
| 4311 | } |
| 4312 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4313 | struct nfs4_cached_acl { |
| 4314 | int cached; |
| 4315 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4316 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4317 | }; |
| 4318 | |
| 4319 | 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] | 4320 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4321 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4322 | |
| 4323 | spin_lock(&inode->i_lock); |
| 4324 | kfree(nfsi->nfs4_acl); |
| 4325 | nfsi->nfs4_acl = acl; |
| 4326 | spin_unlock(&inode->i_lock); |
| 4327 | } |
| 4328 | |
| 4329 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4330 | { |
| 4331 | nfs4_set_cached_acl(inode, NULL); |
| 4332 | } |
| 4333 | |
| 4334 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4335 | { |
| 4336 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4337 | struct nfs4_cached_acl *acl; |
| 4338 | int ret = -ENOENT; |
| 4339 | |
| 4340 | spin_lock(&inode->i_lock); |
| 4341 | acl = nfsi->nfs4_acl; |
| 4342 | if (acl == NULL) |
| 4343 | goto out; |
| 4344 | if (buf == NULL) /* user is just asking for length */ |
| 4345 | goto out_len; |
| 4346 | if (acl->cached == 0) |
| 4347 | goto out; |
| 4348 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4349 | if (acl->len > buflen) |
| 4350 | goto out; |
| 4351 | memcpy(buf, acl->data, acl->len); |
| 4352 | out_len: |
| 4353 | ret = acl->len; |
| 4354 | out: |
| 4355 | spin_unlock(&inode->i_lock); |
| 4356 | return ret; |
| 4357 | } |
| 4358 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4359 | 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] | 4360 | { |
| 4361 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4362 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4363 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4364 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4365 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4366 | if (acl == NULL) |
| 4367 | goto out; |
| 4368 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4369 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4370 | } else { |
| 4371 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4372 | if (acl == NULL) |
| 4373 | goto out; |
| 4374 | acl->cached = 0; |
| 4375 | } |
| 4376 | acl->len = acl_len; |
| 4377 | out: |
| 4378 | nfs4_set_cached_acl(inode, acl); |
| 4379 | } |
| 4380 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4381 | /* |
| 4382 | * The getxattr API returns the required buffer length when called with a |
| 4383 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4384 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4385 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4386 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4387 | * the cache. If not so, we throw away the page, and cache the required |
| 4388 | * length. The next getxattr call will then produce another round trip to |
| 4389 | * the server, this time with the input buf of the required size. |
| 4390 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4391 | 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] | 4392 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4393 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4394 | struct nfs_getaclargs args = { |
| 4395 | .fh = NFS_FH(inode), |
| 4396 | .acl_pages = pages, |
| 4397 | .acl_len = buflen, |
| 4398 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4399 | struct nfs_getaclres res = { |
| 4400 | .acl_len = buflen, |
| 4401 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4402 | struct rpc_message msg = { |
| 4403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4404 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4405 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4406 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4407 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4408 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4409 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4410 | /* As long as we're doing a round trip to the server anyway, |
| 4411 | * let's be prepared for a page of acl data. */ |
| 4412 | if (npages == 0) |
| 4413 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4414 | if (npages > ARRAY_SIZE(pages)) |
| 4415 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4416 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4417 | for (i = 0; i < npages; i++) { |
| 4418 | pages[i] = alloc_page(GFP_KERNEL); |
| 4419 | if (!pages[i]) |
| 4420 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4421 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4422 | |
| 4423 | /* for decoding across pages */ |
| 4424 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4425 | if (!res.acl_scratch) |
| 4426 | goto out_free; |
| 4427 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4428 | args.acl_len = npages * PAGE_SIZE; |
| 4429 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4430 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4431 | 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] | 4432 | __func__, buf, buflen, npages, args.acl_len); |
| 4433 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4434 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4435 | if (ret) |
| 4436 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4437 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4438 | /* Handle the case where the passed-in buffer is too short */ |
| 4439 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4440 | /* Did the user only issue a request for the acl length? */ |
| 4441 | if (buf == NULL) |
| 4442 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4443 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4444 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4445 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4446 | 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] | 4447 | if (buf) { |
| 4448 | if (res.acl_len > buflen) { |
| 4449 | ret = -ERANGE; |
| 4450 | goto out_free; |
| 4451 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4452 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4453 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4454 | out_ok: |
| 4455 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4456 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4457 | for (i = 0; i < npages; i++) |
| 4458 | if (pages[i]) |
| 4459 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4460 | if (res.acl_scratch) |
| 4461 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4462 | return ret; |
| 4463 | } |
| 4464 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4465 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4466 | { |
| 4467 | struct nfs4_exception exception = { }; |
| 4468 | ssize_t ret; |
| 4469 | do { |
| 4470 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4471 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4472 | if (ret >= 0) |
| 4473 | break; |
| 4474 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4475 | } while (exception.retry); |
| 4476 | return ret; |
| 4477 | } |
| 4478 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4479 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4480 | { |
| 4481 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4482 | int ret; |
| 4483 | |
| 4484 | if (!nfs4_server_supports_acls(server)) |
| 4485 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4486 | ret = nfs_revalidate_inode(server, inode); |
| 4487 | if (ret < 0) |
| 4488 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4489 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4490 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4491 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4492 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4493 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4494 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4495 | return ret; |
| 4496 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4499 | 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] | 4500 | { |
| 4501 | struct nfs_server *server = NFS_SERVER(inode); |
| 4502 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4503 | struct nfs_setaclargs arg = { |
| 4504 | .fh = NFS_FH(inode), |
| 4505 | .acl_pages = pages, |
| 4506 | .acl_len = buflen, |
| 4507 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4508 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4509 | struct rpc_message msg = { |
| 4510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4511 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4512 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4513 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4514 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4515 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4516 | |
| 4517 | if (!nfs4_server_supports_acls(server)) |
| 4518 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4519 | if (npages > ARRAY_SIZE(pages)) |
| 4520 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4521 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4522 | if (i < 0) |
| 4523 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4524 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4525 | 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] | 4526 | |
| 4527 | /* |
| 4528 | * Free each page after tx, so the only ref left is |
| 4529 | * held by the network stack |
| 4530 | */ |
| 4531 | for (; i > 0; i--) |
| 4532 | put_page(pages[i-1]); |
| 4533 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4534 | /* |
| 4535 | * Acl update can result in inode attribute update. |
| 4536 | * so mark the attribute cache invalid. |
| 4537 | */ |
| 4538 | spin_lock(&inode->i_lock); |
| 4539 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4540 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4541 | nfs_access_zap_cache(inode); |
| 4542 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4543 | return ret; |
| 4544 | } |
| 4545 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4546 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4547 | { |
| 4548 | struct nfs4_exception exception = { }; |
| 4549 | int err; |
| 4550 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4551 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4552 | trace_nfs4_set_acl(inode, err); |
| 4553 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4554 | &exception); |
| 4555 | } while (exception.retry); |
| 4556 | return err; |
| 4557 | } |
| 4558 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4559 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4560 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4561 | size_t buflen) |
| 4562 | { |
| 4563 | struct nfs_server *server = NFS_SERVER(inode); |
| 4564 | struct nfs_fattr fattr; |
| 4565 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4566 | |
| 4567 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4568 | struct nfs4_getattr_arg args = { |
| 4569 | .fh = NFS_FH(inode), |
| 4570 | .bitmask = bitmask, |
| 4571 | }; |
| 4572 | struct nfs4_getattr_res res = { |
| 4573 | .fattr = &fattr, |
| 4574 | .label = &label, |
| 4575 | .server = server, |
| 4576 | }; |
| 4577 | struct rpc_message msg = { |
| 4578 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 4579 | .rpc_argp = &args, |
| 4580 | .rpc_resp = &res, |
| 4581 | }; |
| 4582 | int ret; |
| 4583 | |
| 4584 | nfs_fattr_init(&fattr); |
| 4585 | |
| 4586 | ret = rpc_call_sync(server->client, &msg, 0); |
| 4587 | if (ret) |
| 4588 | return ret; |
| 4589 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4590 | return -ENOENT; |
| 4591 | if (buflen < label.len) |
| 4592 | return -ERANGE; |
| 4593 | return 0; |
| 4594 | } |
| 4595 | |
| 4596 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4597 | size_t buflen) |
| 4598 | { |
| 4599 | struct nfs4_exception exception = { }; |
| 4600 | int err; |
| 4601 | |
| 4602 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4603 | return -EOPNOTSUPP; |
| 4604 | |
| 4605 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4606 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4607 | trace_nfs4_get_security_label(inode, err); |
| 4608 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4609 | &exception); |
| 4610 | } while (exception.retry); |
| 4611 | return err; |
| 4612 | } |
| 4613 | |
| 4614 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4615 | struct nfs4_label *ilabel, |
| 4616 | struct nfs_fattr *fattr, |
| 4617 | struct nfs4_label *olabel) |
| 4618 | { |
| 4619 | |
| 4620 | struct iattr sattr = {0}; |
| 4621 | struct nfs_server *server = NFS_SERVER(inode); |
| 4622 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
| 4623 | struct nfs_setattrargs args = { |
| 4624 | .fh = NFS_FH(inode), |
| 4625 | .iap = &sattr, |
| 4626 | .server = server, |
| 4627 | .bitmask = bitmask, |
| 4628 | .label = ilabel, |
| 4629 | }; |
| 4630 | struct nfs_setattrres res = { |
| 4631 | .fattr = fattr, |
| 4632 | .label = olabel, |
| 4633 | .server = server, |
| 4634 | }; |
| 4635 | struct rpc_message msg = { |
| 4636 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 4637 | .rpc_argp = &args, |
| 4638 | .rpc_resp = &res, |
| 4639 | }; |
| 4640 | int status; |
| 4641 | |
| 4642 | nfs4_stateid_copy(&args.stateid, &zero_stateid); |
| 4643 | |
| 4644 | status = rpc_call_sync(server->client, &msg, 0); |
| 4645 | if (status) |
| 4646 | dprintk("%s failed: %d\n", __func__, status); |
| 4647 | |
| 4648 | return status; |
| 4649 | } |
| 4650 | |
| 4651 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4652 | struct nfs4_label *ilabel, |
| 4653 | struct nfs_fattr *fattr, |
| 4654 | struct nfs4_label *olabel) |
| 4655 | { |
| 4656 | struct nfs4_exception exception = { }; |
| 4657 | int err; |
| 4658 | |
| 4659 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4660 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4661 | fattr, olabel); |
| 4662 | trace_nfs4_set_security_label(inode, err); |
| 4663 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4664 | &exception); |
| 4665 | } while (exception.retry); |
| 4666 | return err; |
| 4667 | } |
| 4668 | |
| 4669 | static int |
| 4670 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4671 | { |
| 4672 | struct nfs4_label ilabel, *olabel = NULL; |
| 4673 | struct nfs_fattr fattr; |
| 4674 | struct rpc_cred *cred; |
| 4675 | struct inode *inode = dentry->d_inode; |
| 4676 | int status; |
| 4677 | |
| 4678 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4679 | return -EOPNOTSUPP; |
| 4680 | |
| 4681 | nfs_fattr_init(&fattr); |
| 4682 | |
| 4683 | ilabel.pi = 0; |
| 4684 | ilabel.lfs = 0; |
| 4685 | ilabel.label = (char *)buf; |
| 4686 | ilabel.len = buflen; |
| 4687 | |
| 4688 | cred = rpc_lookup_cred(); |
| 4689 | if (IS_ERR(cred)) |
| 4690 | return PTR_ERR(cred); |
| 4691 | |
| 4692 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4693 | if (IS_ERR(olabel)) { |
| 4694 | status = -PTR_ERR(olabel); |
| 4695 | goto out; |
| 4696 | } |
| 4697 | |
| 4698 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4699 | if (status == 0) |
| 4700 | nfs_setsecurity(inode, &fattr, olabel); |
| 4701 | |
| 4702 | nfs4_label_free(olabel); |
| 4703 | out: |
| 4704 | put_rpccred(cred); |
| 4705 | return status; |
| 4706 | } |
| 4707 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4708 | |
| 4709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4711 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4713 | struct nfs_client *clp = server->nfs_client; |
| 4714 | |
| 4715 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | return 0; |
| 4717 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4718 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4719 | case -NFS4ERR_ADMIN_REVOKED: |
| 4720 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4721 | if (state == NULL) |
| 4722 | break; |
| 4723 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4724 | case -NFS4ERR_OPENMODE: |
| 4725 | if (state == NULL) |
| 4726 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4727 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4728 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4729 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4730 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4731 | if (state != NULL) { |
| 4732 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4733 | goto stateid_invalid; |
| 4734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4736 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4737 | nfs4_schedule_lease_recovery(clp); |
| 4738 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4739 | #if defined(CONFIG_NFS_V4_1) |
| 4740 | case -NFS4ERR_BADSESSION: |
| 4741 | case -NFS4ERR_BADSLOT: |
| 4742 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4743 | case -NFS4ERR_DEADSESSION: |
| 4744 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4745 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4746 | case -NFS4ERR_SEQ_MISORDERED: |
| 4747 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4748 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4749 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4750 | task->tk_status = 0; |
| 4751 | return -EAGAIN; |
| 4752 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4754 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4755 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4757 | task->tk_status = 0; |
| 4758 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4759 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | case -NFS4ERR_OLD_STATEID: |
| 4761 | task->tk_status = 0; |
| 4762 | return -EAGAIN; |
| 4763 | } |
| 4764 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4765 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4766 | stateid_invalid: |
| 4767 | task->tk_status = -EIO; |
| 4768 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4769 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4770 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4771 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4772 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4773 | task->tk_status = 0; |
| 4774 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4777 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4778 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4779 | { |
| 4780 | __be32 verf[2]; |
| 4781 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4782 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4783 | /* An impossible timestamp guarantees this value |
| 4784 | * will never match a generated boot time. */ |
| 4785 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4786 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4787 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4788 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4789 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4790 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4791 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4792 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4793 | } |
| 4794 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4795 | static unsigned int |
| 4796 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4797 | char *buf, size_t len) |
| 4798 | { |
| 4799 | unsigned int result; |
| 4800 | |
| 4801 | rcu_read_lock(); |
| 4802 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4803 | clp->cl_ipaddr, |
| 4804 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4805 | RPC_DISPLAY_ADDR), |
| 4806 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4807 | RPC_DISPLAY_PROTO)); |
| 4808 | rcu_read_unlock(); |
| 4809 | return result; |
| 4810 | } |
| 4811 | |
| 4812 | static unsigned int |
| 4813 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4814 | char *buf, size_t len) |
| 4815 | { |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4816 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4817 | |
| 4818 | if (nfs4_client_id_uniquifier[0] != '\0') |
Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4819 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4820 | clp->rpc_ops->version, |
| 4821 | clp->cl_minorversion, |
| 4822 | nfs4_client_id_uniquifier, |
| 4823 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4824 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4825 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4826 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4827 | } |
| 4828 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4829 | /** |
| 4830 | * nfs4_proc_setclientid - Negotiate client ID |
| 4831 | * @clp: state data structure |
| 4832 | * @program: RPC program for NFSv4 callback service |
| 4833 | * @port: IP port number for NFS4 callback service |
| 4834 | * @cred: RPC credential to use for this call |
| 4835 | * @res: where to place the result |
| 4836 | * |
| 4837 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4838 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4839 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4840 | unsigned short port, struct rpc_cred *cred, |
| 4841 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | { |
| 4843 | nfs4_verifier sc_verifier; |
| 4844 | struct nfs4_setclientid setclientid = { |
| 4845 | .sc_verifier = &sc_verifier, |
| 4846 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4847 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | }; |
| 4849 | struct rpc_message msg = { |
| 4850 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4851 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4852 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4853 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4855 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4857 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4858 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4859 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4860 | setclientid.sc_name_len = |
| 4861 | nfs4_init_uniform_client_string(clp, |
| 4862 | setclientid.sc_name, |
| 4863 | sizeof(setclientid.sc_name)); |
| 4864 | else |
| 4865 | setclientid.sc_name_len = |
| 4866 | nfs4_init_nonuniform_client_string(clp, |
| 4867 | setclientid.sc_name, |
| 4868 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4869 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4870 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4871 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4872 | sizeof(setclientid.sc_netid), "%s", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4873 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4874 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4875 | rcu_read_unlock(); |
| 4876 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4877 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4879 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4880 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4881 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4882 | setclientid.sc_name_len, setclientid.sc_name); |
| 4883 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4884 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4885 | dprintk("NFS reply setclientid: %d\n", status); |
| 4886 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4889 | /** |
| 4890 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4891 | * @clp: state data structure |
| 4892 | * @res: result of a previous SETCLIENTID |
| 4893 | * @cred: RPC credential to use for this call |
| 4894 | * |
| 4895 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4896 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4897 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4898 | struct nfs4_setclientid_res *arg, |
| 4899 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | struct rpc_message msg = { |
| 4902 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4903 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4904 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | int status; |
| 4907 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4908 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4909 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4910 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4911 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4912 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4913 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | return status; |
| 4915 | } |
| 4916 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4917 | struct nfs4_delegreturndata { |
| 4918 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4919 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4920 | struct nfs_fh fh; |
| 4921 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4922 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4923 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4924 | int rpc_status; |
| 4925 | }; |
| 4926 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4927 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4928 | { |
| 4929 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4930 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4931 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4932 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4933 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4934 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4935 | switch (task->tk_status) { |
| 4936 | case -NFS4ERR_STALE_STATEID: |
| 4937 | case -NFS4ERR_EXPIRED: |
| 4938 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4939 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4940 | break; |
| 4941 | default: |
| 4942 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4943 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4944 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4945 | return; |
| 4946 | } |
| 4947 | } |
| 4948 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | static void nfs4_delegreturn_release(void *calldata) |
| 4952 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4953 | kfree(calldata); |
| 4954 | } |
| 4955 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4956 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4957 | { |
| 4958 | struct nfs4_delegreturndata *d_data; |
| 4959 | |
| 4960 | d_data = (struct nfs4_delegreturndata *)data; |
| 4961 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4962 | nfs4_setup_sequence(d_data->res.server, |
| 4963 | &d_data->args.seq_args, |
| 4964 | &d_data->res.seq_res, |
| 4965 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4966 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4967 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4968 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4969 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4970 | .rpc_call_done = nfs4_delegreturn_done, |
| 4971 | .rpc_release = nfs4_delegreturn_release, |
| 4972 | }; |
| 4973 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4974 | 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] | 4975 | { |
| 4976 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4977 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4978 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4979 | struct rpc_message msg = { |
| 4980 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4981 | .rpc_cred = cred, |
| 4982 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4983 | struct rpc_task_setup task_setup_data = { |
| 4984 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4985 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4986 | .callback_ops = &nfs4_delegreturn_ops, |
| 4987 | .flags = RPC_TASK_ASYNC, |
| 4988 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4989 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4990 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4991 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4992 | if (data == NULL) |
| 4993 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4994 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4995 | data->args.fhandle = &data->fh; |
| 4996 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4997 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4998 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4999 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5000 | data->res.fattr = &data->fattr; |
| 5001 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5002 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5003 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5004 | data->rpc_status = 0; |
| 5005 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5006 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5007 | msg.rpc_argp = &data->args; |
| 5008 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5009 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5010 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5011 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5012 | if (!issync) |
| 5013 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5014 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5015 | if (status != 0) |
| 5016 | goto out; |
| 5017 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5018 | if (status == 0) |
| 5019 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5020 | else |
| 5021 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5022 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5023 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5024 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | } |
| 5026 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5027 | 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] | 5028 | { |
| 5029 | struct nfs_server *server = NFS_SERVER(inode); |
| 5030 | struct nfs4_exception exception = { }; |
| 5031 | int err; |
| 5032 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5033 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5034 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | switch (err) { |
| 5036 | case -NFS4ERR_STALE_STATEID: |
| 5037 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | case 0: |
| 5039 | return 0; |
| 5040 | } |
| 5041 | err = nfs4_handle_exception(server, err, &exception); |
| 5042 | } while (exception.retry); |
| 5043 | return err; |
| 5044 | } |
| 5045 | |
| 5046 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5047 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5048 | |
| 5049 | /* |
| 5050 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5051 | */ |
| 5052 | static unsigned long |
| 5053 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5054 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5055 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | timeout <<= 1; |
| 5057 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5058 | return NFS4_LOCK_MAXTIMEOUT; |
| 5059 | return timeout; |
| 5060 | } |
| 5061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5063 | { |
| 5064 | struct inode *inode = state->inode; |
| 5065 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5066 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5067 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5069 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5071 | struct nfs_lockt_res res = { |
| 5072 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | }; |
| 5074 | struct rpc_message msg = { |
| 5075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5076 | .rpc_argp = &arg, |
| 5077 | .rpc_resp = &res, |
| 5078 | .rpc_cred = state->owner->so_cred, |
| 5079 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | struct nfs4_lock_state *lsp; |
| 5081 | int status; |
| 5082 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5083 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5084 | status = nfs4_set_lock_state(state, request); |
| 5085 | if (status != 0) |
| 5086 | goto out; |
| 5087 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5088 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5089 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5090 | 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] | 5091 | switch (status) { |
| 5092 | case 0: |
| 5093 | request->fl_type = F_UNLCK; |
| 5094 | break; |
| 5095 | case -NFS4ERR_DENIED: |
| 5096 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5098 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5099 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | return status; |
| 5101 | } |
| 5102 | |
| 5103 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5104 | { |
| 5105 | struct nfs4_exception exception = { }; |
| 5106 | int err; |
| 5107 | |
| 5108 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5109 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5110 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5111 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | &exception); |
| 5113 | } while (exception.retry); |
| 5114 | return err; |
| 5115 | } |
| 5116 | |
| 5117 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5118 | { |
| 5119 | int res = 0; |
| 5120 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5121 | case FL_POSIX: |
| 5122 | res = posix_lock_file_wait(file, fl); |
| 5123 | break; |
| 5124 | case FL_FLOCK: |
| 5125 | res = flock_lock_file_wait(file, fl); |
| 5126 | break; |
| 5127 | default: |
| 5128 | BUG(); |
| 5129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | return res; |
| 5131 | } |
| 5132 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5133 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5134 | struct nfs_locku_args arg; |
| 5135 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5136 | struct nfs4_lock_state *lsp; |
| 5137 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5138 | struct file_lock fl; |
| 5139 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5140 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5141 | }; |
| 5142 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5143 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5144 | struct nfs_open_context *ctx, |
| 5145 | struct nfs4_lock_state *lsp, |
| 5146 | struct nfs_seqid *seqid) |
| 5147 | { |
| 5148 | struct nfs4_unlockdata *p; |
| 5149 | struct inode *inode = lsp->ls_state->inode; |
| 5150 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5151 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5152 | if (p == NULL) |
| 5153 | return NULL; |
| 5154 | p->arg.fh = NFS_FH(inode); |
| 5155 | p->arg.fl = &p->fl; |
| 5156 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5157 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5158 | p->arg.stateid = &lsp->ls_stateid; |
| 5159 | p->lsp = lsp; |
| 5160 | atomic_inc(&lsp->ls_count); |
| 5161 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5162 | p->ctx = get_nfs_open_context(ctx); |
| 5163 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5164 | p->server = NFS_SERVER(inode); |
| 5165 | return p; |
| 5166 | } |
| 5167 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5168 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5169 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5170 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5171 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5172 | nfs4_put_lock_state(calldata->lsp); |
| 5173 | put_nfs_open_context(calldata->ctx); |
| 5174 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5177 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5178 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5179 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5180 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5181 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5182 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5183 | switch (task->tk_status) { |
| 5184 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5185 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 5186 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5187 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5188 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5189 | case -NFS4ERR_BAD_STATEID: |
| 5190 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5191 | case -NFS4ERR_STALE_STATEID: |
| 5192 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5193 | break; |
| 5194 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5195 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5196 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5197 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5198 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5201 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5202 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5203 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5205 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5206 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5207 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5208 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5209 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5210 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5211 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5212 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5213 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5214 | &calldata->res.seq_res, |
| 5215 | task) != 0) |
| 5216 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5217 | return; |
| 5218 | out_no_action: |
| 5219 | task->tk_action = NULL; |
| 5220 | out_wait: |
| 5221 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | } |
| 5223 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5224 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5225 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5226 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5227 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5228 | }; |
| 5229 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5230 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5231 | struct nfs_open_context *ctx, |
| 5232 | struct nfs4_lock_state *lsp, |
| 5233 | struct nfs_seqid *seqid) |
| 5234 | { |
| 5235 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5236 | struct rpc_message msg = { |
| 5237 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5238 | .rpc_cred = ctx->cred, |
| 5239 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5240 | struct rpc_task_setup task_setup_data = { |
| 5241 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5242 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5243 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5244 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5245 | .flags = RPC_TASK_ASYNC, |
| 5246 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5247 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5248 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5249 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5250 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5251 | /* Ensure this is an unlock - when canceling a lock, the |
| 5252 | * canceled lock is passed in, and it won't be an unlock. |
| 5253 | */ |
| 5254 | fl->fl_type = F_UNLCK; |
| 5255 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5256 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5257 | if (data == NULL) { |
| 5258 | nfs_free_seqid(seqid); |
| 5259 | return ERR_PTR(-ENOMEM); |
| 5260 | } |
| 5261 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5262 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5263 | msg.rpc_argp = &data->arg; |
| 5264 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5265 | task_setup_data.callback_data = data; |
| 5266 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5267 | } |
| 5268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5270 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5271 | struct inode *inode = state->inode; |
| 5272 | struct nfs4_state_owner *sp = state->owner; |
| 5273 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5274 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5275 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5276 | struct rpc_task *task; |
| 5277 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5278 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5280 | status = nfs4_set_lock_state(state, request); |
| 5281 | /* Unlock _before_ we do the RPC call */ |
| 5282 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5283 | /* Exclude nfs_delegation_claim_locks() */ |
| 5284 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5285 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5286 | down_read(&nfsi->rwsem); |
| 5287 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5288 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5289 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5290 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5291 | } |
| 5292 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5293 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5294 | if (status != 0) |
| 5295 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5296 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5297 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5298 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5299 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5300 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5301 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5302 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5303 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5304 | 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] | 5305 | status = PTR_ERR(task); |
| 5306 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5307 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5308 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5309 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5310 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5311 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5312 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5313 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | } |
| 5315 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5316 | struct nfs4_lockdata { |
| 5317 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5318 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5319 | struct nfs4_lock_state *lsp; |
| 5320 | struct nfs_open_context *ctx; |
| 5321 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5322 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5323 | int rpc_status; |
| 5324 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5325 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5326 | }; |
| 5327 | |
| 5328 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5329 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5330 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5331 | { |
| 5332 | struct nfs4_lockdata *p; |
| 5333 | struct inode *inode = lsp->ls_state->inode; |
| 5334 | struct nfs_server *server = NFS_SERVER(inode); |
| 5335 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5336 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5337 | if (p == NULL) |
| 5338 | return NULL; |
| 5339 | |
| 5340 | p->arg.fh = NFS_FH(inode); |
| 5341 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5342 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5343 | if (p->arg.open_seqid == NULL) |
| 5344 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5345 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5346 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5347 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5348 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5349 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5350 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5351 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5352 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5353 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5354 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5355 | atomic_inc(&lsp->ls_count); |
| 5356 | p->ctx = get_nfs_open_context(ctx); |
| 5357 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5358 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5359 | out_free_seqid: |
| 5360 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5361 | out_free: |
| 5362 | kfree(p); |
| 5363 | return NULL; |
| 5364 | } |
| 5365 | |
| 5366 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5367 | { |
| 5368 | struct nfs4_lockdata *data = calldata; |
| 5369 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5371 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5372 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5373 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5374 | /* Do we need to do an open_to_lock_owner? */ |
| 5375 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5376 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5377 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5378 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5379 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5380 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5381 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5382 | } else |
| 5383 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5384 | if (!nfs4_valid_open_stateid(state)) { |
| 5385 | data->rpc_status = -EBADF; |
| 5386 | task->tk_action = NULL; |
| 5387 | goto out_release_open_seqid; |
| 5388 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5389 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5390 | if (nfs4_setup_sequence(data->server, |
| 5391 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5392 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5393 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5394 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5395 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5396 | nfs_release_seqid(data->arg.open_seqid); |
| 5397 | out_release_lock_seqid: |
| 5398 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5399 | out_wait: |
| 5400 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5401 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5404 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5405 | { |
| 5406 | struct nfs4_lockdata *data = calldata; |
| 5407 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5408 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5409 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5410 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5411 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5412 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5413 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5414 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5415 | if (data->rpc_status == 0) |
| 5416 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 5417 | else |
| 5418 | goto out; |
| 5419 | } |
| 5420 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5421 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5422 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5423 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5424 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5425 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5426 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | static void nfs4_lock_release(void *calldata) |
| 5430 | { |
| 5431 | struct nfs4_lockdata *data = calldata; |
| 5432 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5433 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5434 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5435 | if (data->cancelled != 0) { |
| 5436 | struct rpc_task *task; |
| 5437 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5438 | data->arg.lock_seqid); |
| 5439 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5440 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5441 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5442 | } else |
| 5443 | nfs_free_seqid(data->arg.lock_seqid); |
| 5444 | nfs4_put_lock_state(data->lsp); |
| 5445 | put_nfs_open_context(data->ctx); |
| 5446 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5447 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5451 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5452 | .rpc_call_done = nfs4_lock_done, |
| 5453 | .rpc_release = nfs4_lock_release, |
| 5454 | }; |
| 5455 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5456 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5457 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5458 | switch (error) { |
| 5459 | case -NFS4ERR_ADMIN_REVOKED: |
| 5460 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5461 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5462 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5463 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5464 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5465 | break; |
| 5466 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5467 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5468 | case -NFS4ERR_EXPIRED: |
| 5469 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5470 | }; |
| 5471 | } |
| 5472 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5473 | 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] | 5474 | { |
| 5475 | struct nfs4_lockdata *data; |
| 5476 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5477 | struct rpc_message msg = { |
| 5478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5479 | .rpc_cred = state->owner->so_cred, |
| 5480 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5481 | struct rpc_task_setup task_setup_data = { |
| 5482 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5483 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5484 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5485 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5486 | .flags = RPC_TASK_ASYNC, |
| 5487 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5488 | int ret; |
| 5489 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5490 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5491 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5492 | fl->fl_u.nfs4_fl.owner, |
| 5493 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5494 | if (data == NULL) |
| 5495 | return -ENOMEM; |
| 5496 | if (IS_SETLKW(cmd)) |
| 5497 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5498 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5499 | msg.rpc_argp = &data->arg; |
| 5500 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5501 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5502 | if (recovery_type > NFS_LOCK_NEW) { |
| 5503 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5504 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5505 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5506 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5507 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5508 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5509 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5510 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5511 | if (ret == 0) { |
| 5512 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5513 | if (ret) |
| 5514 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5515 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5516 | } else |
| 5517 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5518 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5519 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5520 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5524 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5525 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5526 | struct nfs4_exception exception = { |
| 5527 | .inode = state->inode, |
| 5528 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5529 | int err; |
| 5530 | |
| 5531 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5532 | /* Cache the lock if possible... */ |
| 5533 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5534 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5535 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5536 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5537 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5538 | break; |
| 5539 | nfs4_handle_exception(server, err, &exception); |
| 5540 | } while (exception.retry); |
| 5541 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5545 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5546 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5547 | struct nfs4_exception exception = { |
| 5548 | .inode = state->inode, |
| 5549 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5550 | int err; |
| 5551 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5552 | err = nfs4_set_lock_state(state, request); |
| 5553 | if (err != 0) |
| 5554 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5555 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5556 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5557 | return 0; |
| 5558 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5559 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5560 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5561 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5562 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5563 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5564 | switch (err) { |
| 5565 | default: |
| 5566 | goto out; |
| 5567 | case -NFS4ERR_GRACE: |
| 5568 | case -NFS4ERR_DELAY: |
| 5569 | nfs4_handle_exception(server, err, &exception); |
| 5570 | err = 0; |
| 5571 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5572 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5573 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5574 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | } |
| 5576 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5577 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5578 | /** |
| 5579 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5580 | * |
| 5581 | * @state: NFSv4 state for an inode |
| 5582 | * |
| 5583 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5584 | * Otherwise a negative NFS4ERR value is returned. |
| 5585 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5586 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5587 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5588 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5589 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5590 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5591 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5592 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5593 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5594 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5595 | |
| 5596 | status = nfs41_test_stateid(server, |
| 5597 | &lsp->ls_stateid, |
| 5598 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5599 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5600 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5601 | /* Free the stateid unless the server |
| 5602 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5603 | if (status != -NFS4ERR_BAD_STATEID) |
| 5604 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5605 | &lsp->ls_stateid, |
| 5606 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5607 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5608 | ret = status; |
| 5609 | } |
| 5610 | } |
| 5611 | }; |
| 5612 | |
| 5613 | return ret; |
| 5614 | } |
| 5615 | |
| 5616 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5617 | { |
| 5618 | int status = NFS_OK; |
| 5619 | |
| 5620 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5621 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5622 | if (status != NFS_OK) |
| 5623 | status = nfs4_lock_expired(state, request); |
| 5624 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5625 | } |
| 5626 | #endif |
| 5627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5629 | { |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5630 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5631 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5632 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5633 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5634 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5636 | if ((fl_flags & FL_POSIX) && |
| 5637 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5638 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5639 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5640 | status = nfs4_set_lock_state(state, request); |
| 5641 | if (status != 0) |
| 5642 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5643 | request->fl_flags |= FL_ACCESS; |
| 5644 | status = do_vfs_lock(request->fl_file, request); |
| 5645 | if (status < 0) |
| 5646 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5647 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5648 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5649 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5650 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5651 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5652 | status = do_vfs_lock(request->fl_file, request); |
| 5653 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5654 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5655 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5656 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5657 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5658 | if (status != 0) |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5659 | goto out; |
| 5660 | down_read(&nfsi->rwsem); |
| 5661 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5662 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5663 | goto out_unlock; |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5664 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5665 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5666 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5667 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5668 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5669 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5670 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5671 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5672 | out: |
| 5673 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | return status; |
| 5675 | } |
| 5676 | |
| 5677 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5678 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5679 | struct nfs4_exception exception = { |
| 5680 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5681 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5682 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | int err; |
| 5684 | |
| 5685 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5686 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5687 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5688 | if (err == -NFS4ERR_DENIED) |
| 5689 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5691 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | } while (exception.retry); |
| 5693 | return err; |
| 5694 | } |
| 5695 | |
| 5696 | static int |
| 5697 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5698 | { |
| 5699 | struct nfs_open_context *ctx; |
| 5700 | struct nfs4_state *state; |
| 5701 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5702 | int status; |
| 5703 | |
| 5704 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5705 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | state = ctx->state; |
| 5707 | |
| 5708 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5709 | return -EINVAL; |
| 5710 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5711 | if (IS_GETLK(cmd)) { |
| 5712 | if (state != NULL) |
| 5713 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5714 | return 0; |
| 5715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | |
| 5717 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5718 | return -EINVAL; |
| 5719 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5720 | if (request->fl_type == F_UNLCK) { |
| 5721 | if (state != NULL) |
| 5722 | return nfs4_proc_unlck(state, cmd, request); |
| 5723 | return 0; |
| 5724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5726 | if (state == NULL) |
| 5727 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5728 | /* |
| 5729 | * Don't rely on the VFS having checked the file open mode, |
| 5730 | * since it won't do this for flock() locks. |
| 5731 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5732 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5733 | case F_RDLCK: |
| 5734 | if (!(filp->f_mode & FMODE_READ)) |
| 5735 | return -EBADF; |
| 5736 | break; |
| 5737 | case F_WRLCK: |
| 5738 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5739 | return -EBADF; |
| 5740 | } |
| 5741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | do { |
| 5743 | status = nfs4_proc_setlk(state, cmd, request); |
| 5744 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5745 | break; |
| 5746 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5747 | status = -ERESTARTSYS; |
| 5748 | if (signalled()) |
| 5749 | break; |
| 5750 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | return status; |
| 5752 | } |
| 5753 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5754 | 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] | 5755 | { |
| 5756 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5757 | int err; |
| 5758 | |
| 5759 | err = nfs4_set_lock_state(state, fl); |
| 5760 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5761 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5762 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5763 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5764 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5765 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5766 | struct nfs_release_lockowner_data { |
| 5767 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5768 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5769 | struct nfs_release_lockowner_args args; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5770 | struct nfs4_sequence_args seq_args; |
| 5771 | struct nfs4_sequence_res seq_res; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5772 | }; |
| 5773 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5774 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 5775 | { |
| 5776 | struct nfs_release_lockowner_data *data = calldata; |
| 5777 | nfs40_setup_sequence(data->server, |
| 5778 | &data->seq_args, &data->seq_res, task); |
| 5779 | } |
| 5780 | |
| 5781 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 5782 | { |
| 5783 | struct nfs_release_lockowner_data *data = calldata; |
| 5784 | nfs40_sequence_done(task, &data->seq_res); |
| 5785 | } |
| 5786 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5787 | static void nfs4_release_lockowner_release(void *calldata) |
| 5788 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5789 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5790 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5791 | kfree(calldata); |
| 5792 | } |
| 5793 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5794 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5795 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 5796 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5797 | .rpc_release = nfs4_release_lockowner_release, |
| 5798 | }; |
| 5799 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5800 | static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5801 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5802 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5803 | struct rpc_message msg = { |
| 5804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5805 | }; |
| 5806 | |
| 5807 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5808 | return -EINVAL; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5809 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5810 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5811 | if (!data) |
| 5812 | return -ENOMEM; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5813 | nfs4_init_sequence(&data->seq_args, &data->seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5814 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5815 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5816 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5817 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5818 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5819 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5820 | msg.rpc_argp = &data->args; |
| 5821 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5822 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5823 | } |
| 5824 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5825 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5826 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5827 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5828 | const void *buf, size_t buflen, |
| 5829 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5830 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5831 | if (strcmp(key, "") != 0) |
| 5832 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5833 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5834 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5837 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5838 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5839 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5840 | if (strcmp(key, "") != 0) |
| 5841 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5842 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5843 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5844 | } |
| 5845 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5846 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5847 | size_t list_len, const char *name, |
| 5848 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5849 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5850 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5851 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5852 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5853 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5854 | |
| 5855 | if (list && len <= list_len) |
| 5856 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5857 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5858 | } |
| 5859 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5860 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5861 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 5862 | { |
| 5863 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 5864 | } |
| 5865 | |
| 5866 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 5867 | const void *buf, size_t buflen, |
| 5868 | int flags, int type) |
| 5869 | { |
| 5870 | if (security_ismaclabel(key)) |
| 5871 | return nfs4_set_security_label(dentry, buf, buflen); |
| 5872 | |
| 5873 | return -EOPNOTSUPP; |
| 5874 | } |
| 5875 | |
| 5876 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 5877 | void *buf, size_t buflen, int type) |
| 5878 | { |
| 5879 | if (security_ismaclabel(key)) |
| 5880 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); |
| 5881 | return -EOPNOTSUPP; |
| 5882 | } |
| 5883 | |
| 5884 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 5885 | size_t list_len, const char *name, |
| 5886 | size_t name_len, int type) |
| 5887 | { |
| 5888 | size_t len = 0; |
| 5889 | |
| 5890 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { |
| 5891 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); |
| 5892 | if (list && len <= list_len) |
| 5893 | security_inode_listsecurity(dentry->d_inode, list, len); |
| 5894 | } |
| 5895 | return len; |
| 5896 | } |
| 5897 | |
| 5898 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 5899 | .prefix = XATTR_SECURITY_PREFIX, |
| 5900 | .list = nfs4_xattr_list_nfs4_label, |
| 5901 | .get = nfs4_xattr_get_nfs4_label, |
| 5902 | .set = nfs4_xattr_set_nfs4_label, |
| 5903 | }; |
| 5904 | #endif |
| 5905 | |
| 5906 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5907 | /* |
| 5908 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5909 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5910 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5911 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5912 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5913 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5914 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5915 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5916 | return; |
| 5917 | |
| 5918 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5919 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5920 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5921 | fattr->nlink = 2; |
| 5922 | } |
| 5923 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5924 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5925 | const struct qstr *name, |
| 5926 | struct nfs4_fs_locations *fs_locations, |
| 5927 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5928 | { |
| 5929 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5930 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5931 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5932 | }; |
| 5933 | struct nfs4_fs_locations_arg args = { |
| 5934 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5935 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5936 | .page = page, |
| 5937 | .bitmask = bitmask, |
| 5938 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5939 | struct nfs4_fs_locations_res res = { |
| 5940 | .fs_locations = fs_locations, |
| 5941 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5942 | struct rpc_message msg = { |
| 5943 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5944 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5945 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5946 | }; |
| 5947 | int status; |
| 5948 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5949 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5950 | |
| 5951 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5952 | * is not supported */ |
| 5953 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5954 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5955 | else |
| 5956 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5957 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5958 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5959 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5960 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5961 | 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] | 5962 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5963 | return status; |
| 5964 | } |
| 5965 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5966 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5967 | const struct qstr *name, |
| 5968 | struct nfs4_fs_locations *fs_locations, |
| 5969 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5970 | { |
| 5971 | struct nfs4_exception exception = { }; |
| 5972 | int err; |
| 5973 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5974 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 5975 | fs_locations, page); |
| 5976 | trace_nfs4_get_fs_locations(dir, name, err); |
| 5977 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5978 | &exception); |
| 5979 | } while (exception.retry); |
| 5980 | return err; |
| 5981 | } |
| 5982 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5983 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5984 | * If 'use_integrity' is true and the state managment nfs_client |
| 5985 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 5986 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 5987 | * Considerations sections. Otherwise, just use the user cred with the |
| 5988 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5989 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5990 | 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] | 5991 | { |
| 5992 | int status; |
| 5993 | struct nfs4_secinfo_arg args = { |
| 5994 | .dir_fh = NFS_FH(dir), |
| 5995 | .name = name, |
| 5996 | }; |
| 5997 | struct nfs4_secinfo_res res = { |
| 5998 | .flavors = flavors, |
| 5999 | }; |
| 6000 | struct rpc_message msg = { |
| 6001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6002 | .rpc_argp = &args, |
| 6003 | .rpc_resp = &res, |
| 6004 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6005 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
| 6006 | |
| 6007 | if (use_integrity) { |
| 6008 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
| 6009 | msg.rpc_cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6010 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6011 | |
| 6012 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6013 | |
| 6014 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6015 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6016 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6017 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6018 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6019 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6020 | |
| 6021 | if (msg.rpc_cred) |
| 6022 | put_rpccred(msg.rpc_cred); |
| 6023 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6024 | return status; |
| 6025 | } |
| 6026 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6027 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6028 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6029 | { |
| 6030 | struct nfs4_exception exception = { }; |
| 6031 | int err; |
| 6032 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6033 | err = -NFS4ERR_WRONGSEC; |
| 6034 | |
| 6035 | /* try to use integrity protection with machine cred */ |
| 6036 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6037 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6038 | |
| 6039 | /* |
| 6040 | * if unable to use integrity protection, or SECINFO with |
| 6041 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6042 | * disallowed by spec, but exists in deployed servers) use |
| 6043 | * the current filesystem's rpc_client and the user cred. |
| 6044 | */ |
| 6045 | if (err == -NFS4ERR_WRONGSEC) |
| 6046 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6047 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6048 | trace_nfs4_secinfo(dir, name, err); |
| 6049 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6050 | &exception); |
| 6051 | } while (exception.retry); |
| 6052 | return err; |
| 6053 | } |
| 6054 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6055 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6056 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6057 | * Check the exchange flags returned by the server for invalid flags, having |
| 6058 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6059 | * DS flags set. |
| 6060 | */ |
| 6061 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6062 | { |
| 6063 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6064 | goto out_inval; |
| 6065 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6066 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6067 | goto out_inval; |
| 6068 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6069 | goto out_inval; |
| 6070 | return NFS_OK; |
| 6071 | out_inval: |
| 6072 | return -NFS4ERR_INVAL; |
| 6073 | } |
| 6074 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6075 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6076 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6077 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6078 | { |
| 6079 | if (a->server_scope_sz == b->server_scope_sz && |
| 6080 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6081 | return true; |
| 6082 | |
| 6083 | return false; |
| 6084 | } |
| 6085 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6086 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6087 | * nfs4_proc_bind_conn_to_session() |
| 6088 | * |
| 6089 | * The 4.1 client currently uses the same TCP connection for the |
| 6090 | * fore and backchannel. |
| 6091 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6092 | 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] | 6093 | { |
| 6094 | int status; |
| 6095 | struct nfs41_bind_conn_to_session_res res; |
| 6096 | struct rpc_message msg = { |
| 6097 | .rpc_proc = |
| 6098 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 6099 | .rpc_argp = clp, |
| 6100 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6101 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6102 | }; |
| 6103 | |
| 6104 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6105 | |
| 6106 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 6107 | if (unlikely(res.session == NULL)) { |
| 6108 | status = -ENOMEM; |
| 6109 | goto out; |
| 6110 | } |
| 6111 | |
| 6112 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6113 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6114 | if (status == 0) { |
| 6115 | if (memcmp(res.session->sess_id.data, |
| 6116 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6117 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6118 | status = -EIO; |
| 6119 | goto out_session; |
| 6120 | } |
| 6121 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 6122 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6123 | __func__); |
| 6124 | status = -EIO; |
| 6125 | goto out_session; |
| 6126 | } |
| 6127 | if (res.use_conn_in_rdma_mode) { |
| 6128 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6129 | __func__); |
| 6130 | status = -EIO; |
| 6131 | goto out_session; |
| 6132 | } |
| 6133 | } |
| 6134 | out_session: |
| 6135 | kfree(res.session); |
| 6136 | out: |
| 6137 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6138 | return status; |
| 6139 | } |
| 6140 | |
| 6141 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6142 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6143 | * 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] | 6144 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6145 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6146 | .how = SP4_MACH_CRED, |
| 6147 | .enforce.u.words = { |
| 6148 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6149 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6150 | 1 << (OP_CREATE_SESSION - 32) | |
| 6151 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6152 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6153 | }, |
| 6154 | .allow.u.words = { |
| 6155 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6156 | 1 << (OP_LOCKU), |
| 6157 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6158 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6159 | 1 << (OP_TEST_STATEID - 32) | |
| 6160 | 1 << (OP_FREE_STATEID - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6161 | } |
| 6162 | }; |
| 6163 | |
| 6164 | /* |
| 6165 | * Select the state protection mode for client `clp' given the server results |
| 6166 | * from exchange_id in `sp'. |
| 6167 | * |
| 6168 | * Returns 0 on success, negative errno otherwise. |
| 6169 | */ |
| 6170 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6171 | struct nfs41_state_protection *sp) |
| 6172 | { |
| 6173 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6174 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6175 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6176 | 1 << (OP_CREATE_SESSION - 32) | |
| 6177 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6178 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6179 | }; |
| 6180 | unsigned int i; |
| 6181 | |
| 6182 | if (sp->how == SP4_MACH_CRED) { |
| 6183 | /* Print state protect result */ |
| 6184 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6185 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6186 | if (test_bit(i, sp->enforce.u.longs)) |
| 6187 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6188 | if (test_bit(i, sp->allow.u.longs)) |
| 6189 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6190 | } |
| 6191 | |
| 6192 | /* make sure nothing is on enforce list that isn't supported */ |
| 6193 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6194 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6195 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6196 | return -EINVAL; |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | /* |
| 6201 | * Minimal mode - state operations are allowed to use machine |
| 6202 | * credential. Note this already happens by default, so the |
| 6203 | * client doesn't have to do anything more than the negotiation. |
| 6204 | * |
| 6205 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6206 | * we're already using the machine cred for exchange_id |
| 6207 | * and will never use a different cred. |
| 6208 | */ |
| 6209 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6210 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6211 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6212 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6213 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6214 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6215 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6216 | } else { |
| 6217 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6218 | return -EINVAL; |
| 6219 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6220 | |
| 6221 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6222 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6223 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6224 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6225 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6226 | |
| 6227 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6228 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6229 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6230 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6231 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6232 | |
| 6233 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6234 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6235 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6236 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6237 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6238 | |
| 6239 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6240 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6241 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6242 | } |
| 6243 | |
| 6244 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6245 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6246 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6247 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | return 0; |
| 6251 | } |
| 6252 | |
| 6253 | /* |
| 6254 | * _nfs4_proc_exchange_id() |
| 6255 | * |
| 6256 | * Wrapper for EXCHANGE_ID operation. |
| 6257 | */ |
| 6258 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6259 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6260 | { |
| 6261 | nfs4_verifier verifier; |
| 6262 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6263 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6264 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6265 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6266 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6267 | }; |
| 6268 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6269 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6270 | }; |
| 6271 | int status; |
| 6272 | struct rpc_message msg = { |
| 6273 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6274 | .rpc_argp = &args, |
| 6275 | .rpc_resp = &res, |
| 6276 | .rpc_cred = cred, |
| 6277 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6278 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6279 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6280 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 6281 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6282 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 6283 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 6284 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6285 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6286 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6287 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6288 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6289 | status = -ENOMEM; |
| 6290 | goto out; |
| 6291 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6292 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6293 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6294 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6295 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6296 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6297 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6300 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6301 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6302 | status = -ENOMEM; |
| 6303 | goto out_server_scope; |
| 6304 | } |
| 6305 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6306 | switch (sp4_how) { |
| 6307 | case SP4_NONE: |
| 6308 | args.state_protect.how = SP4_NONE; |
| 6309 | break; |
| 6310 | |
| 6311 | case SP4_MACH_CRED: |
| 6312 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6313 | break; |
| 6314 | |
| 6315 | default: |
| 6316 | /* unsupported! */ |
| 6317 | WARN_ON_ONCE(1); |
| 6318 | status = -EINVAL; |
| 6319 | goto out_server_scope; |
| 6320 | } |
| 6321 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6322 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6323 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6324 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6325 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6326 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6327 | if (status == 0) |
| 6328 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6329 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6330 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6331 | clp->cl_clientid = res.clientid; |
| 6332 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 6333 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 6334 | clp->cl_seqid = res.seqid; |
| 6335 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6336 | kfree(clp->cl_serverowner); |
| 6337 | clp->cl_serverowner = res.server_owner; |
| 6338 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6339 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6340 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6341 | kfree(clp->cl_implid); |
| 6342 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6343 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6344 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6345 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6346 | res.server_scope)) { |
| 6347 | dprintk("%s: server_scope mismatch detected\n", |
| 6348 | __func__); |
| 6349 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6350 | kfree(clp->cl_serverscope); |
| 6351 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6352 | } |
| 6353 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6354 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6355 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6356 | goto out; |
| 6357 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6358 | } else |
| 6359 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6360 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6361 | out_server_owner: |
| 6362 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6363 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6364 | kfree(res.server_scope); |
| 6365 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6366 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6367 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6368 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6369 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6370 | clp->cl_implid->date.seconds, |
| 6371 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6372 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6373 | return status; |
| 6374 | } |
| 6375 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6376 | /* |
| 6377 | * nfs4_proc_exchange_id() |
| 6378 | * |
| 6379 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 6380 | * |
| 6381 | * Since the clientid has expired, all compounds using sessions |
| 6382 | * associated with the stale clientid will be returning |
| 6383 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 6384 | * be in some phase of session reset. |
| 6385 | * |
| 6386 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 6387 | */ |
| 6388 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 6389 | { |
| 6390 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 6391 | int status; |
| 6392 | |
| 6393 | /* try SP4_MACH_CRED if krb5i/p */ |
| 6394 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 6395 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 6396 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 6397 | if (!status) |
| 6398 | return 0; |
| 6399 | } |
| 6400 | |
| 6401 | /* try SP4_NONE */ |
| 6402 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 6403 | } |
| 6404 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6405 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6406 | struct rpc_cred *cred) |
| 6407 | { |
| 6408 | struct rpc_message msg = { |
| 6409 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 6410 | .rpc_argp = clp, |
| 6411 | .rpc_cred = cred, |
| 6412 | }; |
| 6413 | int status; |
| 6414 | |
| 6415 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6416 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6417 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6418 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6419 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 6420 | return status; |
| 6421 | } |
| 6422 | |
| 6423 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 6424 | struct rpc_cred *cred) |
| 6425 | { |
| 6426 | unsigned int loop; |
| 6427 | int ret; |
| 6428 | |
| 6429 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 6430 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 6431 | switch (ret) { |
| 6432 | case -NFS4ERR_DELAY: |
| 6433 | case -NFS4ERR_CLIENTID_BUSY: |
| 6434 | ssleep(1); |
| 6435 | break; |
| 6436 | default: |
| 6437 | return ret; |
| 6438 | } |
| 6439 | } |
| 6440 | return 0; |
| 6441 | } |
| 6442 | |
| 6443 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 6444 | { |
| 6445 | struct rpc_cred *cred; |
| 6446 | int ret = 0; |
| 6447 | |
| 6448 | if (clp->cl_mvops->minor_version < 1) |
| 6449 | goto out; |
| 6450 | if (clp->cl_exchange_flags == 0) |
| 6451 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6452 | if (clp->cl_preserve_clid) |
| 6453 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6454 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6455 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 6456 | if (cred) |
| 6457 | put_rpccred(cred); |
| 6458 | switch (ret) { |
| 6459 | case 0: |
| 6460 | case -NFS4ERR_STALE_CLIENTID: |
| 6461 | clp->cl_exchange_flags = 0; |
| 6462 | } |
| 6463 | out: |
| 6464 | return ret; |
| 6465 | } |
| 6466 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6467 | struct nfs4_get_lease_time_data { |
| 6468 | struct nfs4_get_lease_time_args *args; |
| 6469 | struct nfs4_get_lease_time_res *res; |
| 6470 | struct nfs_client *clp; |
| 6471 | }; |
| 6472 | |
| 6473 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 6474 | void *calldata) |
| 6475 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6476 | struct nfs4_get_lease_time_data *data = |
| 6477 | (struct nfs4_get_lease_time_data *)calldata; |
| 6478 | |
| 6479 | dprintk("--> %s\n", __func__); |
| 6480 | /* just setup sequence, do not trigger session recovery |
| 6481 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6482 | nfs41_setup_sequence(data->clp->cl_session, |
| 6483 | &data->args->la_seq_args, |
| 6484 | &data->res->lr_seq_res, |
| 6485 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6486 | dprintk("<-- %s\n", __func__); |
| 6487 | } |
| 6488 | |
| 6489 | /* |
| 6490 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 6491 | * from sequence operation or clientid errors. |
| 6492 | */ |
| 6493 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 6494 | { |
| 6495 | struct nfs4_get_lease_time_data *data = |
| 6496 | (struct nfs4_get_lease_time_data *)calldata; |
| 6497 | |
| 6498 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6499 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 6500 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6501 | switch (task->tk_status) { |
| 6502 | case -NFS4ERR_DELAY: |
| 6503 | case -NFS4ERR_GRACE: |
| 6504 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 6505 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 6506 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6507 | /* fall through */ |
| 6508 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6509 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6510 | return; |
| 6511 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6512 | dprintk("<-- %s\n", __func__); |
| 6513 | } |
| 6514 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6515 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6516 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 6517 | .rpc_call_done = nfs4_get_lease_time_done, |
| 6518 | }; |
| 6519 | |
| 6520 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 6521 | { |
| 6522 | struct rpc_task *task; |
| 6523 | struct nfs4_get_lease_time_args args; |
| 6524 | struct nfs4_get_lease_time_res res = { |
| 6525 | .lr_fsinfo = fsinfo, |
| 6526 | }; |
| 6527 | struct nfs4_get_lease_time_data data = { |
| 6528 | .args = &args, |
| 6529 | .res = &res, |
| 6530 | .clp = clp, |
| 6531 | }; |
| 6532 | struct rpc_message msg = { |
| 6533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 6534 | .rpc_argp = &args, |
| 6535 | .rpc_resp = &res, |
| 6536 | }; |
| 6537 | struct rpc_task_setup task_setup = { |
| 6538 | .rpc_client = clp->cl_rpcclient, |
| 6539 | .rpc_message = &msg, |
| 6540 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6541 | .callback_data = &data, |
| 6542 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6543 | }; |
| 6544 | int status; |
| 6545 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6546 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6547 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6548 | dprintk("--> %s\n", __func__); |
| 6549 | task = rpc_run_task(&task_setup); |
| 6550 | |
| 6551 | if (IS_ERR(task)) |
| 6552 | status = PTR_ERR(task); |
| 6553 | else { |
| 6554 | status = task->tk_status; |
| 6555 | rpc_put_task(task); |
| 6556 | } |
| 6557 | dprintk("<-- %s return %d\n", __func__, status); |
| 6558 | |
| 6559 | return status; |
| 6560 | } |
| 6561 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6562 | /* |
| 6563 | * Initialize the values to be used by the client in CREATE_SESSION |
| 6564 | * If nfs4_init_session set the fore channel request and response sizes, |
| 6565 | * use them. |
| 6566 | * |
| 6567 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 6568 | * always set csa_cachethis to FALSE because the current implementation |
| 6569 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 6570 | */ |
| 6571 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 6572 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6573 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6574 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6575 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 6576 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 6577 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6578 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6579 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 6580 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6581 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6582 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6583 | |
| 6584 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6585 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6586 | __func__, |
| 6587 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6588 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6589 | |
| 6590 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6591 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 6592 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 6593 | args->bc_attrs.max_resp_sz_cached = 0; |
| 6594 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 6595 | args->bc_attrs.max_reqs = 1; |
| 6596 | |
| 6597 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 6598 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 6599 | __func__, |
| 6600 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 6601 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 6602 | args->bc_attrs.max_reqs); |
| 6603 | } |
| 6604 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6605 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6606 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6607 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 6608 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 6609 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6610 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 6611 | return -EINVAL; |
| 6612 | /* |
| 6613 | * Our requested max_ops is the minimum we need; we're not |
| 6614 | * prepared to break up compounds into smaller pieces than that. |
| 6615 | * So, no point even trying to continue if the server won't |
| 6616 | * cooperate: |
| 6617 | */ |
| 6618 | if (rcvd->max_ops < sent->max_ops) |
| 6619 | return -EINVAL; |
| 6620 | if (rcvd->max_reqs == 0) |
| 6621 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6622 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 6623 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6624 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6625 | } |
| 6626 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6627 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 6628 | { |
| 6629 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 6630 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6631 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6632 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 6633 | return -EINVAL; |
| 6634 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 6635 | return -EINVAL; |
| 6636 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 6637 | return -EINVAL; |
| 6638 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6639 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6640 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6641 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6642 | return -EINVAL; |
| 6643 | return 0; |
| 6644 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6645 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6646 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 6647 | struct nfs4_session *session) |
| 6648 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6649 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6650 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6651 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 6652 | if (ret) |
| 6653 | return ret; |
| 6654 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6655 | } |
| 6656 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6657 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 6658 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6659 | { |
| 6660 | struct nfs4_session *session = clp->cl_session; |
| 6661 | struct nfs41_create_session_args args = { |
| 6662 | .client = clp, |
| 6663 | .cb_program = NFS4_CALLBACK, |
| 6664 | }; |
| 6665 | struct nfs41_create_session_res res = { |
| 6666 | .client = clp, |
| 6667 | }; |
| 6668 | struct rpc_message msg = { |
| 6669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 6670 | .rpc_argp = &args, |
| 6671 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6672 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6673 | }; |
| 6674 | int status; |
| 6675 | |
| 6676 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6677 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6678 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6679 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6680 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6681 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6682 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6683 | /* Verify the session's negotiated channel_attrs values */ |
| 6684 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6685 | /* Increment the clientid slot sequence id */ |
| 6686 | clp->cl_seqid++; |
| 6687 | } |
| 6688 | |
| 6689 | return status; |
| 6690 | } |
| 6691 | |
| 6692 | /* |
| 6693 | * Issues a CREATE_SESSION operation to the server. |
| 6694 | * It is the responsibility of the caller to verify the session is |
| 6695 | * expired before calling this routine. |
| 6696 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6697 | 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] | 6698 | { |
| 6699 | int status; |
| 6700 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6701 | struct nfs4_session *session = clp->cl_session; |
| 6702 | |
| 6703 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 6704 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6705 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6706 | if (status) |
| 6707 | goto out; |
| 6708 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6709 | /* Init or reset the session slot tables */ |
| 6710 | status = nfs4_setup_session_slot_tables(session); |
| 6711 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6712 | if (status) |
| 6713 | goto out; |
| 6714 | |
| 6715 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 6716 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 6717 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6718 | out: |
| 6719 | dprintk("<-- %s\n", __func__); |
| 6720 | return status; |
| 6721 | } |
| 6722 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6723 | /* |
| 6724 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 6725 | * The caller must serialize access to this routine. |
| 6726 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6727 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 6728 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6729 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6730 | struct rpc_message msg = { |
| 6731 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 6732 | .rpc_argp = session, |
| 6733 | .rpc_cred = cred, |
| 6734 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6735 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6736 | |
| 6737 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 6738 | |
| 6739 | /* session is still being setup */ |
| 6740 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 6741 | return status; |
| 6742 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6743 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6744 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6745 | |
| 6746 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6747 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6748 | "Session has been destroyed regardless...\n", status); |
| 6749 | |
| 6750 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 6751 | return status; |
| 6752 | } |
| 6753 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6754 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6755 | * Renew the cl_session lease. |
| 6756 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6757 | struct nfs4_sequence_data { |
| 6758 | struct nfs_client *clp; |
| 6759 | struct nfs4_sequence_args args; |
| 6760 | struct nfs4_sequence_res res; |
| 6761 | }; |
| 6762 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6763 | static void nfs41_sequence_release(void *data) |
| 6764 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6765 | struct nfs4_sequence_data *calldata = data; |
| 6766 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6767 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6768 | if (atomic_read(&clp->cl_count) > 1) |
| 6769 | nfs4_schedule_state_renewal(clp); |
| 6770 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6771 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6772 | } |
| 6773 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6774 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6775 | { |
| 6776 | switch(task->tk_status) { |
| 6777 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6778 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6779 | return -EAGAIN; |
| 6780 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6781 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6782 | } |
| 6783 | return 0; |
| 6784 | } |
| 6785 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6786 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6787 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6788 | struct nfs4_sequence_data *calldata = data; |
| 6789 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6790 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6791 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6792 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6793 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6794 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6795 | if (task->tk_status < 0) { |
| 6796 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6797 | if (atomic_read(&clp->cl_count) == 1) |
| 6798 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6799 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6800 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6801 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6802 | return; |
| 6803 | } |
| 6804 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6805 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6806 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6807 | dprintk("<-- %s\n", __func__); |
| 6808 | } |
| 6809 | |
| 6810 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6811 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6812 | struct nfs4_sequence_data *calldata = data; |
| 6813 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6814 | struct nfs4_sequence_args *args; |
| 6815 | struct nfs4_sequence_res *res; |
| 6816 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6817 | args = task->tk_msg.rpc_argp; |
| 6818 | res = task->tk_msg.rpc_resp; |
| 6819 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6820 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6824 | .rpc_call_done = nfs41_sequence_call_done, |
| 6825 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6826 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6827 | }; |
| 6828 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6829 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6830 | struct rpc_cred *cred, |
| 6831 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6832 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6833 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6834 | struct rpc_message msg = { |
| 6835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6836 | .rpc_cred = cred, |
| 6837 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6838 | struct rpc_task_setup task_setup_data = { |
| 6839 | .rpc_client = clp->cl_rpcclient, |
| 6840 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6841 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6842 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6843 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6844 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6845 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6846 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6847 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6848 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6849 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6850 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6851 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6852 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6853 | if (is_privileged) |
| 6854 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6855 | msg.rpc_argp = &calldata->args; |
| 6856 | msg.rpc_resp = &calldata->res; |
| 6857 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6858 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6859 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6860 | return rpc_run_task(&task_setup_data); |
| 6861 | } |
| 6862 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6863 | 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] | 6864 | { |
| 6865 | struct rpc_task *task; |
| 6866 | int ret = 0; |
| 6867 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6868 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6869 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6870 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6871 | if (IS_ERR(task)) |
| 6872 | ret = PTR_ERR(task); |
| 6873 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6874 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6875 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6876 | return ret; |
| 6877 | } |
| 6878 | |
| 6879 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6880 | { |
| 6881 | struct rpc_task *task; |
| 6882 | int ret; |
| 6883 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6884 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6885 | if (IS_ERR(task)) { |
| 6886 | ret = PTR_ERR(task); |
| 6887 | goto out; |
| 6888 | } |
| 6889 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6890 | if (!ret) { |
| 6891 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6892 | |
| 6893 | if (task->tk_status == 0) |
| 6894 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6895 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6896 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6897 | rpc_put_task(task); |
| 6898 | out: |
| 6899 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6900 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6901 | } |
| 6902 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6903 | struct nfs4_reclaim_complete_data { |
| 6904 | struct nfs_client *clp; |
| 6905 | struct nfs41_reclaim_complete_args arg; |
| 6906 | struct nfs41_reclaim_complete_res res; |
| 6907 | }; |
| 6908 | |
| 6909 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6910 | { |
| 6911 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6912 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6913 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6914 | &calldata->arg.seq_args, |
| 6915 | &calldata->res.seq_res, |
| 6916 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6917 | } |
| 6918 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6919 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6920 | { |
| 6921 | switch(task->tk_status) { |
| 6922 | case 0: |
| 6923 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6924 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6925 | break; |
| 6926 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6927 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6928 | /* fall through */ |
| 6929 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6930 | return -EAGAIN; |
| 6931 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6932 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6933 | } |
| 6934 | return 0; |
| 6935 | } |
| 6936 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6937 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6938 | { |
| 6939 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6940 | struct nfs_client *clp = calldata->clp; |
| 6941 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6942 | |
| 6943 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6944 | if (!nfs41_sequence_done(task, res)) |
| 6945 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6946 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6947 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6948 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6949 | rpc_restart_call_prepare(task); |
| 6950 | return; |
| 6951 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6952 | dprintk("<-- %s\n", __func__); |
| 6953 | } |
| 6954 | |
| 6955 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6956 | { |
| 6957 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6958 | |
| 6959 | kfree(calldata); |
| 6960 | } |
| 6961 | |
| 6962 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6963 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6964 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6965 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6966 | }; |
| 6967 | |
| 6968 | /* |
| 6969 | * Issue a global reclaim complete. |
| 6970 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6971 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6972 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6973 | { |
| 6974 | struct nfs4_reclaim_complete_data *calldata; |
| 6975 | struct rpc_task *task; |
| 6976 | struct rpc_message msg = { |
| 6977 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6978 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6979 | }; |
| 6980 | struct rpc_task_setup task_setup_data = { |
| 6981 | .rpc_client = clp->cl_rpcclient, |
| 6982 | .rpc_message = &msg, |
| 6983 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6984 | .flags = RPC_TASK_ASYNC, |
| 6985 | }; |
| 6986 | int status = -ENOMEM; |
| 6987 | |
| 6988 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6989 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6990 | if (calldata == NULL) |
| 6991 | goto out; |
| 6992 | calldata->clp = clp; |
| 6993 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6994 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6995 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6996 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6997 | msg.rpc_argp = &calldata->arg; |
| 6998 | msg.rpc_resp = &calldata->res; |
| 6999 | task_setup_data.callback_data = calldata; |
| 7000 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7001 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7002 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7003 | goto out; |
| 7004 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7005 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7006 | if (status == 0) |
| 7007 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7008 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7009 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7010 | out: |
| 7011 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7012 | return status; |
| 7013 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7014 | |
| 7015 | static void |
| 7016 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7017 | { |
| 7018 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7019 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7020 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7021 | |
| 7022 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7023 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7024 | * right now covering the LAYOUTGET we are about to send. |
| 7025 | * However, that is not so catastrophic, and there seems |
| 7026 | * to be no way to prevent it completely. |
| 7027 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7028 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7029 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7030 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7031 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7032 | NFS_I(lgp->args.inode)->layout, |
| 7033 | lgp->args.ctx->state)) { |
| 7034 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7035 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7039 | { |
| 7040 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7041 | struct inode *inode = lgp->args.inode; |
| 7042 | struct nfs_server *server = NFS_SERVER(inode); |
| 7043 | struct pnfs_layout_hdr *lo; |
| 7044 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7045 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7046 | |
| 7047 | dprintk("--> %s\n", __func__); |
| 7048 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7049 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7050 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7051 | |
| 7052 | switch (task->tk_status) { |
| 7053 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7054 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7055 | case -NFS4ERR_LAYOUTTRYLATER: |
| 7056 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7057 | timeo = rpc_get_timeout(task->tk_client); |
| 7058 | giveup = lgp->args.timestamp + timeo; |
| 7059 | if (time_after(giveup, jiffies)) |
| 7060 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7061 | break; |
| 7062 | case -NFS4ERR_EXPIRED: |
| 7063 | case -NFS4ERR_BAD_STATEID: |
| 7064 | spin_lock(&inode->i_lock); |
| 7065 | lo = NFS_I(inode)->layout; |
| 7066 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7067 | spin_unlock(&inode->i_lock); |
| 7068 | /* If the open stateid was bad, then recover it. */ |
| 7069 | state = lgp->args.ctx->state; |
| 7070 | } else { |
| 7071 | LIST_HEAD(head); |
| 7072 | |
| 7073 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7074 | spin_unlock(&inode->i_lock); |
| 7075 | /* Mark the bad layout state as invalid, then |
| 7076 | * retry using the open stateid. */ |
| 7077 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7078 | } |
| 7079 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7080 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 7081 | rpc_restart_call_prepare(task); |
| 7082 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7083 | dprintk("<-- %s\n", __func__); |
| 7084 | } |
| 7085 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7086 | static size_t max_response_pages(struct nfs_server *server) |
| 7087 | { |
| 7088 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7089 | return nfs_page_array_len(0, max_resp_sz); |
| 7090 | } |
| 7091 | |
| 7092 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7093 | { |
| 7094 | int i; |
| 7095 | |
| 7096 | if (!pages) |
| 7097 | return; |
| 7098 | |
| 7099 | for (i = 0; i < size; i++) { |
| 7100 | if (!pages[i]) |
| 7101 | break; |
| 7102 | __free_page(pages[i]); |
| 7103 | } |
| 7104 | kfree(pages); |
| 7105 | } |
| 7106 | |
| 7107 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7108 | { |
| 7109 | struct page **pages; |
| 7110 | int i; |
| 7111 | |
| 7112 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7113 | if (!pages) { |
| 7114 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7115 | return NULL; |
| 7116 | } |
| 7117 | |
| 7118 | for (i = 0; i < size; i++) { |
| 7119 | pages[i] = alloc_page(gfp_flags); |
| 7120 | if (!pages[i]) { |
| 7121 | dprintk("%s: failed to allocate page\n", __func__); |
| 7122 | nfs4_free_pages(pages, size); |
| 7123 | return NULL; |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | return pages; |
| 7128 | } |
| 7129 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7130 | static void nfs4_layoutget_release(void *calldata) |
| 7131 | { |
| 7132 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7133 | struct inode *inode = lgp->args.inode; |
| 7134 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7135 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7136 | |
| 7137 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7138 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7139 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7140 | put_nfs_open_context(lgp->args.ctx); |
| 7141 | kfree(calldata); |
| 7142 | dprintk("<-- %s\n", __func__); |
| 7143 | } |
| 7144 | |
| 7145 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7146 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7147 | .rpc_call_done = nfs4_layoutget_done, |
| 7148 | .rpc_release = nfs4_layoutget_release, |
| 7149 | }; |
| 7150 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7151 | struct pnfs_layout_segment * |
| 7152 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7153 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7154 | struct inode *inode = lgp->args.inode; |
| 7155 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7156 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7157 | struct rpc_task *task; |
| 7158 | struct rpc_message msg = { |
| 7159 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7160 | .rpc_argp = &lgp->args, |
| 7161 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7162 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7163 | }; |
| 7164 | struct rpc_task_setup task_setup_data = { |
| 7165 | .rpc_client = server->client, |
| 7166 | .rpc_message = &msg, |
| 7167 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7168 | .callback_data = lgp, |
| 7169 | .flags = RPC_TASK_ASYNC, |
| 7170 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7171 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7172 | int status = 0; |
| 7173 | |
| 7174 | dprintk("--> %s\n", __func__); |
| 7175 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7176 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7177 | if (!lgp->args.layout.pages) { |
| 7178 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7179 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7180 | } |
| 7181 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7182 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7183 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7184 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7185 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7186 | 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] | 7187 | |
| 7188 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7189 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7190 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7191 | task = rpc_run_task(&task_setup_data); |
| 7192 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7193 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7194 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7195 | if (status == 0) |
| 7196 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7197 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7198 | &lgp->args.range, |
| 7199 | &lgp->res.range, |
| 7200 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7201 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7202 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7203 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7204 | rpc_put_task(task); |
| 7205 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7206 | if (status) |
| 7207 | return ERR_PTR(status); |
| 7208 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7209 | } |
| 7210 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7211 | static void |
| 7212 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7213 | { |
| 7214 | struct nfs4_layoutreturn *lrp = calldata; |
| 7215 | |
| 7216 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7217 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7218 | &lrp->args.seq_args, |
| 7219 | &lrp->res.seq_res, |
| 7220 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7224 | { |
| 7225 | struct nfs4_layoutreturn *lrp = calldata; |
| 7226 | struct nfs_server *server; |
| 7227 | |
| 7228 | dprintk("--> %s\n", __func__); |
| 7229 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7230 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7231 | return; |
| 7232 | |
| 7233 | server = NFS_SERVER(lrp->args.inode); |
| 7234 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7235 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7236 | return; |
| 7237 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7238 | dprintk("<-- %s\n", __func__); |
| 7239 | } |
| 7240 | |
| 7241 | static void nfs4_layoutreturn_release(void *calldata) |
| 7242 | { |
| 7243 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7244 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7245 | |
| 7246 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7247 | spin_lock(&lo->plh_inode->i_lock); |
| 7248 | if (lrp->res.lrs_present) |
| 7249 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7250 | lo->plh_block_lgets--; |
| 7251 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7252 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7253 | kfree(calldata); |
| 7254 | dprintk("<-- %s\n", __func__); |
| 7255 | } |
| 7256 | |
| 7257 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7258 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7259 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7260 | .rpc_release = nfs4_layoutreturn_release, |
| 7261 | }; |
| 7262 | |
| 7263 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 7264 | { |
| 7265 | struct rpc_task *task; |
| 7266 | struct rpc_message msg = { |
| 7267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7268 | .rpc_argp = &lrp->args, |
| 7269 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7270 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7271 | }; |
| 7272 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7273 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7274 | .rpc_message = &msg, |
| 7275 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7276 | .callback_data = lrp, |
| 7277 | }; |
| 7278 | int status; |
| 7279 | |
| 7280 | dprintk("--> %s\n", __func__); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7281 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7282 | task = rpc_run_task(&task_setup_data); |
| 7283 | if (IS_ERR(task)) |
| 7284 | return PTR_ERR(task); |
| 7285 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7286 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7287 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7288 | rpc_put_task(task); |
| 7289 | return status; |
| 7290 | } |
| 7291 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 7292 | /* |
| 7293 | * Retrieve the list of Data Server devices from the MDS. |
| 7294 | */ |
| 7295 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 7296 | const struct nfs_fh *fh, |
| 7297 | struct pnfs_devicelist *devlist) |
| 7298 | { |
| 7299 | struct nfs4_getdevicelist_args args = { |
| 7300 | .fh = fh, |
| 7301 | .layoutclass = server->pnfs_curr_ld->id, |
| 7302 | }; |
| 7303 | struct nfs4_getdevicelist_res res = { |
| 7304 | .devlist = devlist, |
| 7305 | }; |
| 7306 | struct rpc_message msg = { |
| 7307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 7308 | .rpc_argp = &args, |
| 7309 | .rpc_resp = &res, |
| 7310 | }; |
| 7311 | int status; |
| 7312 | |
| 7313 | dprintk("--> %s\n", __func__); |
| 7314 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 7315 | &res.seq_res, 0); |
| 7316 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7317 | return status; |
| 7318 | } |
| 7319 | |
| 7320 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 7321 | const struct nfs_fh *fh, |
| 7322 | struct pnfs_devicelist *devlist) |
| 7323 | { |
| 7324 | struct nfs4_exception exception = { }; |
| 7325 | int err; |
| 7326 | |
| 7327 | do { |
| 7328 | err = nfs4_handle_exception(server, |
| 7329 | _nfs4_getdevicelist(server, fh, devlist), |
| 7330 | &exception); |
| 7331 | } while (exception.retry); |
| 7332 | |
| 7333 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 7334 | err, devlist->num_devs); |
| 7335 | |
| 7336 | return err; |
| 7337 | } |
| 7338 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 7339 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7340 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7341 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7342 | struct pnfs_device *pdev, |
| 7343 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7344 | { |
| 7345 | struct nfs4_getdeviceinfo_args args = { |
| 7346 | .pdev = pdev, |
| 7347 | }; |
| 7348 | struct nfs4_getdeviceinfo_res res = { |
| 7349 | .pdev = pdev, |
| 7350 | }; |
| 7351 | struct rpc_message msg = { |
| 7352 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 7353 | .rpc_argp = &args, |
| 7354 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7355 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7356 | }; |
| 7357 | int status; |
| 7358 | |
| 7359 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7360 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7361 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7362 | |
| 7363 | return status; |
| 7364 | } |
| 7365 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7366 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 7367 | struct pnfs_device *pdev, |
| 7368 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7369 | { |
| 7370 | struct nfs4_exception exception = { }; |
| 7371 | int err; |
| 7372 | |
| 7373 | do { |
| 7374 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7375 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7376 | &exception); |
| 7377 | } while (exception.retry); |
| 7378 | return err; |
| 7379 | } |
| 7380 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 7381 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7382 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 7383 | { |
| 7384 | struct nfs4_layoutcommit_data *data = calldata; |
| 7385 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7386 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7387 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7388 | nfs41_setup_sequence(session, |
| 7389 | &data->args.seq_args, |
| 7390 | &data->res.seq_res, |
| 7391 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | static void |
| 7395 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 7396 | { |
| 7397 | struct nfs4_layoutcommit_data *data = calldata; |
| 7398 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 7399 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7400 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7401 | return; |
| 7402 | |
| 7403 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7404 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 7405 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 7406 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 7407 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7408 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7409 | break; |
| 7410 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7411 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7412 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7413 | break; |
| 7414 | default: |
| 7415 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 7416 | rpc_restart_call_prepare(task); |
| 7417 | return; |
| 7418 | } |
| 7419 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | static void nfs4_layoutcommit_release(void *calldata) |
| 7423 | { |
| 7424 | struct nfs4_layoutcommit_data *data = calldata; |
| 7425 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7426 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7427 | put_rpccred(data->cred); |
| 7428 | kfree(data); |
| 7429 | } |
| 7430 | |
| 7431 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 7432 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 7433 | .rpc_call_done = nfs4_layoutcommit_done, |
| 7434 | .rpc_release = nfs4_layoutcommit_release, |
| 7435 | }; |
| 7436 | |
| 7437 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7438 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7439 | { |
| 7440 | struct rpc_message msg = { |
| 7441 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 7442 | .rpc_argp = &data->args, |
| 7443 | .rpc_resp = &data->res, |
| 7444 | .rpc_cred = data->cred, |
| 7445 | }; |
| 7446 | struct rpc_task_setup task_setup_data = { |
| 7447 | .task = &data->task, |
| 7448 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 7449 | .rpc_message = &msg, |
| 7450 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7451 | .callback_data = data, |
| 7452 | .flags = RPC_TASK_ASYNC, |
| 7453 | }; |
| 7454 | struct rpc_task *task; |
| 7455 | int status = 0; |
| 7456 | |
| 7457 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 7458 | "lbw: %llu inode %lu\n", |
| 7459 | data->task.tk_pid, sync, |
| 7460 | data->args.lastbytewritten, |
| 7461 | data->args.inode->i_ino); |
| 7462 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7463 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7464 | task = rpc_run_task(&task_setup_data); |
| 7465 | if (IS_ERR(task)) |
| 7466 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7467 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7468 | goto out; |
| 7469 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7470 | if (status != 0) |
| 7471 | goto out; |
| 7472 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7473 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7474 | out: |
| 7475 | dprintk("%s: status %d\n", __func__, status); |
| 7476 | rpc_put_task(task); |
| 7477 | return status; |
| 7478 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7479 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7480 | /** |
| 7481 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 7482 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 7483 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7484 | static int |
| 7485 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7486 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7487 | { |
| 7488 | struct nfs41_secinfo_no_name_args args = { |
| 7489 | .style = SECINFO_STYLE_CURRENT_FH, |
| 7490 | }; |
| 7491 | struct nfs4_secinfo_res res = { |
| 7492 | .flavors = flavors, |
| 7493 | }; |
| 7494 | struct rpc_message msg = { |
| 7495 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 7496 | .rpc_argp = &args, |
| 7497 | .rpc_resp = &res, |
| 7498 | }; |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7499 | return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg, |
| 7500 | &args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7501 | } |
| 7502 | |
| 7503 | static int |
| 7504 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7505 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 7506 | { |
| 7507 | struct nfs4_exception exception = { }; |
| 7508 | int err; |
| 7509 | do { |
| 7510 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7511 | switch (err) { |
| 7512 | case 0: |
| 7513 | case -NFS4ERR_WRONGSEC: |
| 7514 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7515 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7516 | default: |
| 7517 | err = nfs4_handle_exception(server, err, &exception); |
| 7518 | } |
| 7519 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7520 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7521 | return err; |
| 7522 | } |
| 7523 | |
| 7524 | static int |
| 7525 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 7526 | struct nfs_fsinfo *info) |
| 7527 | { |
| 7528 | int err; |
| 7529 | struct page *page; |
| 7530 | rpc_authflavor_t flavor; |
| 7531 | struct nfs4_secinfo_flavors *flavors; |
| 7532 | |
| 7533 | page = alloc_page(GFP_KERNEL); |
| 7534 | if (!page) { |
| 7535 | err = -ENOMEM; |
| 7536 | goto out; |
| 7537 | } |
| 7538 | |
| 7539 | flavors = page_address(page); |
| 7540 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 7541 | |
| 7542 | /* |
| 7543 | * Fall back on "guess and check" method if |
| 7544 | * the server doesn't support SECINFO_NO_NAME |
| 7545 | */ |
| 7546 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 7547 | err = nfs4_find_root_sec(server, fhandle, info); |
| 7548 | goto out_freepage; |
| 7549 | } |
| 7550 | if (err) |
| 7551 | goto out_freepage; |
| 7552 | |
| 7553 | flavor = nfs_find_best_sec(flavors); |
| 7554 | if (err == 0) |
| 7555 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 7556 | |
| 7557 | out_freepage: |
| 7558 | put_page(page); |
| 7559 | if (err == -EACCES) |
| 7560 | return -EPERM; |
| 7561 | out: |
| 7562 | return err; |
| 7563 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7564 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7565 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 7566 | nfs4_stateid *stateid, |
| 7567 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7568 | { |
| 7569 | int status; |
| 7570 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7571 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7572 | }; |
| 7573 | struct nfs41_test_stateid_res res; |
| 7574 | struct rpc_message msg = { |
| 7575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 7576 | .rpc_argp = &args, |
| 7577 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7578 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7579 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7580 | struct rpc_clnt *rpc_client = server->client; |
| 7581 | |
| 7582 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 7583 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7584 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7585 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7586 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7587 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7588 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7589 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7590 | if (status != NFS_OK) { |
| 7591 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7592 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7593 | } |
| 7594 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7595 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7596 | } |
| 7597 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7598 | /** |
| 7599 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 7600 | * |
| 7601 | * @server: server / transport on which to perform the operation |
| 7602 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7603 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7604 | * |
| 7605 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 7606 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 7607 | * failed or the state ID is not currently valid. |
| 7608 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7609 | static int nfs41_test_stateid(struct nfs_server *server, |
| 7610 | nfs4_stateid *stateid, |
| 7611 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7612 | { |
| 7613 | struct nfs4_exception exception = { }; |
| 7614 | int err; |
| 7615 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7616 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7617 | if (err != -NFS4ERR_DELAY) |
| 7618 | break; |
| 7619 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7620 | } while (exception.retry); |
| 7621 | return err; |
| 7622 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7623 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7624 | struct nfs_free_stateid_data { |
| 7625 | struct nfs_server *server; |
| 7626 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7627 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7628 | }; |
| 7629 | |
| 7630 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 7631 | { |
| 7632 | struct nfs_free_stateid_data *data = calldata; |
| 7633 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 7634 | &data->args.seq_args, |
| 7635 | &data->res.seq_res, |
| 7636 | task); |
| 7637 | } |
| 7638 | |
| 7639 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 7640 | { |
| 7641 | struct nfs_free_stateid_data *data = calldata; |
| 7642 | |
| 7643 | nfs41_sequence_done(task, &data->res.seq_res); |
| 7644 | |
| 7645 | switch (task->tk_status) { |
| 7646 | case -NFS4ERR_DELAY: |
| 7647 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 7648 | rpc_restart_call_prepare(task); |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | static void nfs41_free_stateid_release(void *calldata) |
| 7653 | { |
| 7654 | kfree(calldata); |
| 7655 | } |
| 7656 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7657 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7658 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 7659 | .rpc_call_done = nfs41_free_stateid_done, |
| 7660 | .rpc_release = nfs41_free_stateid_release, |
| 7661 | }; |
| 7662 | |
| 7663 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 7664 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7665 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7666 | bool privileged) |
| 7667 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7668 | struct rpc_message msg = { |
| 7669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7670 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7671 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7672 | struct rpc_task_setup task_setup = { |
| 7673 | .rpc_client = server->client, |
| 7674 | .rpc_message = &msg, |
| 7675 | .callback_ops = &nfs41_free_stateid_ops, |
| 7676 | .flags = RPC_TASK_ASYNC, |
| 7677 | }; |
| 7678 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7679 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7680 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 7681 | &task_setup.rpc_client, &msg); |
| 7682 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7683 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7684 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7685 | if (!data) |
| 7686 | return ERR_PTR(-ENOMEM); |
| 7687 | data->server = server; |
| 7688 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 7689 | |
| 7690 | task_setup.callback_data = data; |
| 7691 | |
| 7692 | msg.rpc_argp = &data->args; |
| 7693 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7694 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7695 | if (privileged) |
| 7696 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 7697 | |
| 7698 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7699 | } |
| 7700 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7701 | /** |
| 7702 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 7703 | * |
| 7704 | * @server: server / transport on which to perform the operation |
| 7705 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7706 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7707 | * |
| 7708 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 7709 | * negative NFS4ERR value is returned. |
| 7710 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7711 | static int nfs41_free_stateid(struct nfs_server *server, |
| 7712 | nfs4_stateid *stateid, |
| 7713 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7714 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7715 | struct rpc_task *task; |
| 7716 | int ret; |
| 7717 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7718 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7719 | if (IS_ERR(task)) |
| 7720 | return PTR_ERR(task); |
| 7721 | ret = rpc_wait_for_completion_task(task); |
| 7722 | if (!ret) |
| 7723 | ret = task->tk_status; |
| 7724 | rpc_put_task(task); |
| 7725 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7726 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7727 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7728 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 7729 | { |
| 7730 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7731 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7732 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7733 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7734 | nfs4_free_lock_state(server, lsp); |
| 7735 | if (IS_ERR(task)) |
| 7736 | return PTR_ERR(task); |
| 7737 | rpc_put_task(task); |
| 7738 | return 0; |
| 7739 | } |
| 7740 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7741 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 7742 | const nfs4_stateid *s2) |
| 7743 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7744 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7745 | return false; |
| 7746 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7747 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7748 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7749 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7750 | return true; |
| 7751 | |
| 7752 | return false; |
| 7753 | } |
| 7754 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7755 | #endif /* CONFIG_NFS_V4_1 */ |
| 7756 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7757 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 7758 | const nfs4_stateid *s2) |
| 7759 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7760 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7761 | } |
| 7762 | |
| 7763 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7764 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7765 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7766 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7767 | .recover_open = nfs4_open_reclaim, |
| 7768 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7769 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7770 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7771 | }; |
| 7772 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7773 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7774 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7775 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 7776 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 7777 | .recover_open = nfs4_open_reclaim, |
| 7778 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7779 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7780 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7781 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7782 | }; |
| 7783 | #endif /* CONFIG_NFS_V4_1 */ |
| 7784 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7785 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7786 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7787 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7788 | .recover_open = nfs4_open_expired, |
| 7789 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7790 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7791 | }; |
| 7792 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7793 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7794 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7795 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7796 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7797 | .recover_open = nfs41_open_expired, |
| 7798 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7799 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7800 | }; |
| 7801 | #endif /* CONFIG_NFS_V4_1 */ |
| 7802 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7803 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7804 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7805 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7806 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7807 | }; |
| 7808 | |
| 7809 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7810 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7811 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7812 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7813 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7814 | }; |
| 7815 | #endif |
| 7816 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7817 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7818 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7819 | .init_caps = NFS_CAP_READDIRPLUS |
| 7820 | | NFS_CAP_ATOMIC_OPEN |
| 7821 | | NFS_CAP_CHANGE_ATTR |
| 7822 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7823 | .init_client = nfs40_init_client, |
| 7824 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7825 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7826 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7827 | .free_lock_state = nfs4_release_lockowner, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7828 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7829 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7830 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7831 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7832 | }; |
| 7833 | |
| 7834 | #if defined(CONFIG_NFS_V4_1) |
| 7835 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7836 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7837 | .init_caps = NFS_CAP_READDIRPLUS |
| 7838 | | NFS_CAP_ATOMIC_OPEN |
| 7839 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7840 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7841 | | NFS_CAP_STATEID_NFSV41 |
| 7842 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7843 | .init_client = nfs41_init_client, |
| 7844 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7845 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7846 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7847 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7848 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7849 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7850 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7851 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7852 | }; |
| 7853 | #endif |
| 7854 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7855 | #if defined(CONFIG_NFS_V4_2) |
| 7856 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 7857 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7858 | .init_caps = NFS_CAP_READDIRPLUS |
| 7859 | | NFS_CAP_ATOMIC_OPEN |
| 7860 | | NFS_CAP_CHANGE_ATTR |
| 7861 | | NFS_CAP_POSIX_LOCK |
| 7862 | | NFS_CAP_STATEID_NFSV41 |
| 7863 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7864 | .init_client = nfs41_init_client, |
| 7865 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7866 | .match_stateid = nfs41_match_stateid, |
| 7867 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7868 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7869 | .call_sync_ops = &nfs41_call_sync_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7870 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7871 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7872 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 7873 | }; |
| 7874 | #endif |
| 7875 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7876 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7877 | [0] = &nfs_v4_0_minor_ops, |
| 7878 | #if defined(CONFIG_NFS_V4_1) |
| 7879 | [1] = &nfs_v4_1_minor_ops, |
| 7880 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7881 | #if defined(CONFIG_NFS_V4_2) |
| 7882 | [2] = &nfs_v4_2_minor_ops, |
| 7883 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7884 | }; |
| 7885 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7886 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7887 | .create = nfs_create, |
| 7888 | .lookup = nfs_lookup, |
| 7889 | .atomic_open = nfs_atomic_open, |
| 7890 | .link = nfs_link, |
| 7891 | .unlink = nfs_unlink, |
| 7892 | .symlink = nfs_symlink, |
| 7893 | .mkdir = nfs_mkdir, |
| 7894 | .rmdir = nfs_rmdir, |
| 7895 | .mknod = nfs_mknod, |
| 7896 | .rename = nfs_rename, |
| 7897 | .permission = nfs_permission, |
| 7898 | .getattr = nfs_getattr, |
| 7899 | .setattr = nfs_setattr, |
| 7900 | .getxattr = generic_getxattr, |
| 7901 | .setxattr = generic_setxattr, |
| 7902 | .listxattr = generic_listxattr, |
| 7903 | .removexattr = generic_removexattr, |
| 7904 | }; |
| 7905 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7906 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7907 | .permission = nfs_permission, |
| 7908 | .getattr = nfs_getattr, |
| 7909 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7910 | .getxattr = generic_getxattr, |
| 7911 | .setxattr = generic_setxattr, |
| 7912 | .listxattr = generic_listxattr, |
| 7913 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7914 | }; |
| 7915 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7916 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7917 | .version = 4, /* protocol version */ |
| 7918 | .dentry_ops = &nfs4_dentry_operations, |
| 7919 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7920 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7921 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7922 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7923 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7924 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7925 | .getattr = nfs4_proc_getattr, |
| 7926 | .setattr = nfs4_proc_setattr, |
| 7927 | .lookup = nfs4_proc_lookup, |
| 7928 | .access = nfs4_proc_access, |
| 7929 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7930 | .create = nfs4_proc_create, |
| 7931 | .remove = nfs4_proc_remove, |
| 7932 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7933 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7934 | .unlink_done = nfs4_proc_unlink_done, |
| 7935 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7936 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7937 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7938 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7939 | .link = nfs4_proc_link, |
| 7940 | .symlink = nfs4_proc_symlink, |
| 7941 | .mkdir = nfs4_proc_mkdir, |
| 7942 | .rmdir = nfs4_proc_remove, |
| 7943 | .readdir = nfs4_proc_readdir, |
| 7944 | .mknod = nfs4_proc_mknod, |
| 7945 | .statfs = nfs4_proc_statfs, |
| 7946 | .fsinfo = nfs4_proc_fsinfo, |
| 7947 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7948 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7949 | .decode_dirent = nfs4_decode_dirent, |
| 7950 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7951 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7952 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7953 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7954 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7955 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7956 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7957 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7958 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7959 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7960 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7961 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7962 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7963 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7964 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7965 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7966 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7967 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7968 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7969 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7970 | .create_server = nfs4_create_server, |
| 7971 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7972 | }; |
| 7973 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7974 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7975 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7976 | .list = nfs4_xattr_list_nfs4_acl, |
| 7977 | .get = nfs4_xattr_get_nfs4_acl, |
| 7978 | .set = nfs4_xattr_set_nfs4_acl, |
| 7979 | }; |
| 7980 | |
| 7981 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7982 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7983 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 7984 | &nfs4_xattr_nfs4_label_handler, |
| 7985 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7986 | NULL |
| 7987 | }; |
| 7988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7989 | /* |
| 7990 | * Local variables: |
| 7991 | * c-basic-offset: 8 |
| 7992 | * End: |
| 7993 | */ |